Make PolySet cache global

stl_dim
Marius Kintel 2011-09-09 06:10:33 +02:00
parent cbba974d3a
commit 09cc0496f7
2 changed files with 9 additions and 7 deletions

View File

@ -9,13 +9,15 @@
class.
*/
QCache<std::string, PolySetEvaluator::cache_entry> 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());
}

View File

@ -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<std::string, cache_entry> cache;
static QCache<std::string, cache_entry> cache;
private:
const Tree &tree;