Skip to content

Commit

Permalink
Add debug output for the Node Id Cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
t-paul committed Dec 16, 2014
1 parent 7bea0be commit 4be9a43
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/Tree.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Tree.h"
#include "nodedumper.h"
#include "printutils.h"

#include <assert.h>
#include <algorithm>
Expand Down Expand Up @@ -31,11 +32,6 @@ const std::string &Tree::getString(const AbstractNode &node) const
return this->nodecache[node];
}

static bool filter(char c)
{
return c == ' ' || c == '\n' || c == '\t' || c == '\r';
}

/*!
Returns the cached ID string representation of the subtree rooted by \a node.
If node is not cached, the cache will be rebuilt.
Expand All @@ -47,16 +43,22 @@ static bool filter(char c)
const std::string &Tree::getIdString(const AbstractNode &node) const
{
assert(this->root_node);

if (!this->nodeidcache.contains(node)) {
const std::string &str = getString(node);
const std::string &nodestr = getString(node);
const boost::regex re("[^\\s\\\"]+|\\\"(?:[^\\\"\\\\]|\\\\.)*\\\"");
std::stringstream sstream;
boost::sregex_token_iterator i(str.begin(), str.end(), re, 0);
std::copy(i, boost::sregex_token_iterator(), std::ostream_iterator<std::string>(sstream));
boost::sregex_token_iterator i(nodestr.begin(), nodestr.end(), re, 0);
std::copy(i, boost::sregex_token_iterator(), std::ostream_iterator<std::string>(sstream));

return this->nodeidcache.insert(node, sstream.str());
const std::string & result = this->nodeidcache.insert(node, sstream.str());
PRINTDB("Id Cache MISS: %s", result);
return result;
} else {
const std::string & result = this->nodeidcache[node];
PRINTDB("Id Cache HIT: %s", result);
return result;
}
return this->nodeidcache[node];
}

/*!
Expand Down

0 comments on commit 4be9a43

Please sign in to comment.