diff options
author | Marius Kintel <marius@kintel.net> | 2011-09-11 08:51:55 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2011-09-11 08:51:55 (GMT) |
commit | 95949cf961d84f65ad9bfb9f2dec7361059ca515 (patch) | |
tree | b5d50e381362d013d8cce12c524571f013a990a2 /src/Tree.cc | |
parent | 18e97e0bd3f6bda4fdcd17de2a85173ba59b6b00 (diff) |
Implemented CGAL caching
Diffstat (limited to 'src/Tree.cc')
-rw-r--r-- | src/Tree.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/Tree.cc b/src/Tree.cc index e791e12..68cb2bf 100644 --- a/src/Tree.cc +++ b/src/Tree.cc @@ -21,6 +21,30 @@ 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. + + The difference between this method and getString() is that the ID string + is stripped for whitespace. Especially indentation whitespace is important to + strip to enable cache hits for equivalent nodes from different scopes. +*/ +const std::string &Tree::getIdString(const AbstractNode &node) const +{ + assert(this->root_node); + if (!this->nodeidcache.contains(node)) { + std::string str = getString(node); + str.erase(std::remove_if(str.begin(), str.end(), filter), str.end()); + return this->nodeidcache.insert(node, str); + } + return this->nodeidcache[node]; +} + /*! Sets a new root. Will clear the existing cache. */ |