diff options
author | Marius Kintel <marius@kintel.net> | 2011-09-11 05:33:18 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2011-09-11 05:33:18 (GMT) |
commit | c0641d6916775309d64944ca121cc736f0c8d7a1 (patch) | |
tree | 801e0b5d67d13ff4773c5906c9cb68d271a2be02 /src/PolySetEvaluator.cc | |
parent | 09cc0496f7ce61e2bcbce80e067e0fac8054599a (diff) |
Reenabled PolySet caching. Pass shared_ptrs to polysets around to better manage memory
Diffstat (limited to 'src/PolySetEvaluator.cc')
-rw-r--r-- | src/PolySetEvaluator.cc | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/PolySetEvaluator.cc b/src/PolySetEvaluator.cc index 6426d6e..a2bdca5 100644 --- a/src/PolySetEvaluator.cc +++ b/src/PolySetEvaluator.cc @@ -11,18 +11,26 @@ QCache<std::string, PolySetEvaluator::cache_entry> PolySetEvaluator::cache(100000); -PolySet *PolySetEvaluator::getPolySet(const AbstractNode &node) +/*! + Factory method returning a PolySet from the given node. If the + node is already cached, the cached PolySet will be returned + otherwise a new PolySet will be created from the node. If cache is + true, the newly created PolySet will be cached. + */ +shared_ptr<PolySet> PolySetEvaluator::getPolySet(const AbstractNode &node, bool cache) { - const string &cacheid = this->tree.getString(node); - if (cache.contains(cacheid)) return cache[cacheid]->ps; + std::string cacheid = this->tree.getString(node); + if (this->cache.contains(cacheid)) { + PRINTF("Cache hit: %s", cacheid.substr(0, 40).c_str()); + return this->cache[cacheid]->ps; + } - PolySet *ps = node.evaluate_polyset(this); - cache.insert(cacheid, new cache_entry(ps), ps?ps->polygons.size():0); + shared_ptr<PolySet> ps(node.evaluate_polyset(this)); + if (cache) this->cache.insert(cacheid, new cache_entry(ps), ps?ps->polygons.size():0); return ps; } -PolySetEvaluator::cache_entry::cache_entry(PolySet *ps) - : ps(ps) +PolySetEvaluator::cache_entry::cache_entry(const shared_ptr<PolySet> &ps) : ps(ps) { if (print_messages_stack.size() > 0) this->msg = print_messages_stack.last(); } |