diff options
author | Don Bright <hugh.m.bright@gmail.com> | 2011-09-12 22:40:51 (GMT) |
---|---|---|
committer | Don Bright <hugh.m.bright@gmail.com> | 2011-09-12 22:40:51 (GMT) |
commit | f5f06c8e976ca45aebea42fe8c04bf7404357ac8 (patch) | |
tree | 8d0cdd2698e7806c1b12cc49e743b561e1082961 /src/Tree.cc | |
parent | 007c40848db9efd704694f2e7596cabed80da50f (diff) | |
parent | 5ac9162f1c67fd21737ead11d7ebc638bf4eef5f (diff) |
merge
Merge remote branch 'upstream/visitor' into visitortests
Conflicts:
src/export.cc
src/openscad.cc
src/polyset.cc
src/transform.cc
tests/CMakeLists.txt
tests/FindGLEW.cmake
tests/csgtermtest.cc
Diffstat (limited to 'src/Tree.cc')
-rw-r--r-- | src/Tree.cc | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/Tree.cc b/src/Tree.cc index a451f24..7c4866b 100644 --- a/src/Tree.cc +++ b/src/Tree.cc @@ -2,15 +2,18 @@ #include "nodedumper.h" #include <assert.h> +#include <algorithm> /*! - Returns the cached string representation of the subtree rootet by \a node. + Returns the cached string representation of the subtree rooted by \a node. If node is not cached, the cache will be rebuilt. */ const std::string &Tree::getString(const AbstractNode &node) const { assert(this->root_node); if (!this->nodecache.contains(node)) { + this->nodecache.clear(); + this->nodeidcache.clear(); NodeDumper dumper(this->nodecache, false); Traverser trav(dumper, *this->root_node, Traverser::PRE_AND_POSTFIX); trav.execute(); @@ -20,6 +23,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. */ |