From 09cc0496f7ce61e2bcbce80e067e0fac8054599a Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Fri, 9 Sep 2011 06:10:33 +0200 Subject: [PATCH] Make PolySet cache global --- src/PolySetEvaluator.cc | 10 ++++++---- src/PolySetEvaluator.h | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/PolySetEvaluator.cc b/src/PolySetEvaluator.cc index 28086869..6426d6e2 100644 --- a/src/PolySetEvaluator.cc +++ b/src/PolySetEvaluator.cc @@ -9,13 +9,15 @@ class. */ +QCache PolySetEvaluator::cache(100000); + PolySet *PolySetEvaluator::getPolySet(const AbstractNode &node) { const string &cacheid = this->tree.getString(node); - if (this->cache.contains(cacheid)) return this->cache[cacheid]->ps; + if (cache.contains(cacheid)) return cache[cacheid]->ps; PolySet *ps = node.evaluate_polyset(this); - this->cache.insert(cacheid, new cache_entry(ps), ps?ps->polygons.size():0); + cache.insert(cacheid, new cache_entry(ps), ps?ps->polygons.size():0); return ps; } @@ -27,6 +29,6 @@ PolySetEvaluator::cache_entry::cache_entry(PolySet *ps) void PolySetEvaluator::printCache() { - PRINTF("PolySets in cache: %d", this->cache.size()); - PRINTF("Polygons in cache: %d", this->cache.totalCost()); + PRINTF("PolySets in cache: %d", cache.size()); + PRINTF("Polygons in cache: %d", cache.totalCost()); } diff --git a/src/PolySetEvaluator.h b/src/PolySetEvaluator.h index 1a97cb5e..b7c490d7 100644 --- a/src/PolySetEvaluator.h +++ b/src/PolySetEvaluator.h @@ -9,7 +9,7 @@ class PolySetEvaluator { public: - PolySetEvaluator(const Tree &tree) : cache(100000), tree(tree) {} + PolySetEvaluator(const Tree &tree) : tree(tree) {} virtual ~PolySetEvaluator() {} const Tree &getTree() const { return this->tree; } @@ -23,7 +23,7 @@ public: virtual PolySet *evaluatePolySet(const class RenderNode &) { return NULL; } void clearCache() { - this->cache.clear(); + cache.clear(); } void printCache(); protected: @@ -35,7 +35,7 @@ protected: ~cache_entry() { } }; - QCache cache; + static QCache cache; private: const Tree &tree;