diff --git a/src/Tree.cc b/src/Tree.cc index 9e67b923..7264d89d 100644 --- a/src/Tree.cc +++ b/src/Tree.cc @@ -1,5 +1,6 @@ #include "Tree.h" #include "nodedumper.h" +#include "printutils.h" #include #include @@ -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(sstream)); + boost::sregex_token_iterator i(nodestr.begin(), nodestr.end(), re, 0); + std::copy(i, boost::sregex_token_iterator(), std::ostream_iterator(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]; } /*!