Add debug output for the Node Id Cache.

master
Torsten Paul 2014-12-16 21:21:06 +01:00
parent 7bea0bef37
commit 4be9a43b40
1 changed files with 12 additions and 10 deletions

View File

@ -1,5 +1,6 @@
#include "Tree.h"
#include "nodedumper.h"
#include "printutils.h"
#include <assert.h>
#include <algorithm>
@ -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.
@ -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];
}
/*!