summaryrefslogtreecommitdiff
path: root/src/PolySetEvaluator.cc
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2011-09-11 07:10:31 (GMT)
committerMarius Kintel <marius@kintel.net>2011-09-11 07:10:31 (GMT)
commit18e97e0bd3f6bda4fdcd17de2a85173ba59b6b00 (patch)
tree327ec7c648e0f01a2673672ebe83c3524c971e19 /src/PolySetEvaluator.cc
parent9afeded46c0e9023002dc04ba6131adcb39762b1 (diff)
Fixed bug introduced by the new PolySet cache; string filtering done in the wrong place, refactored cache into separate class
Diffstat (limited to 'src/PolySetEvaluator.cc')
-rw-r--r--src/PolySetEvaluator.cc28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/PolySetEvaluator.cc b/src/PolySetEvaluator.cc
index a2bdca5..e46ae59 100644
--- a/src/PolySetEvaluator.cc
+++ b/src/PolySetEvaluator.cc
@@ -1,3 +1,4 @@
+#include "PolySetCache.h"
#include "PolySetEvaluator.h"
#include "printutils.h"
#include "polyset.h"
@@ -9,7 +10,10 @@
class.
*/
-QCache<std::string, PolySetEvaluator::cache_entry> PolySetEvaluator::cache(100000);
+static bool filter(char c)
+{
+ return c == ' ' || c == '\n' || c == '\t' || c == '\r';
+}
/*!
Factory method returning a PolySet from the given node. If the
@@ -20,23 +24,15 @@ QCache<std::string, PolySetEvaluator::cache_entry> PolySetEvaluator::cache(10000
shared_ptr<PolySet> PolySetEvaluator::getPolySet(const AbstractNode &node, bool cache)
{
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;
+ cacheid.erase(std::remove_if(cacheid.begin(), cacheid.end(), filter), cacheid.end());
+
+ if (PolySetCache::instance()->contains(cacheid)) {
+// For cache debugging
+// PRINTF("Cache hit: %s", cacheid.substr(0, 40).c_str());
+ return PolySetCache::instance()->get(cacheid);
}
shared_ptr<PolySet> ps(node.evaluate_polyset(this));
- if (cache) this->cache.insert(cacheid, new cache_entry(ps), ps?ps->polygons.size():0);
+ if (cache) PolySetCache::instance()->insert(cacheid, ps);
return 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();
-}
-
-void PolySetEvaluator::printCache()
-{
- PRINTF("PolySets in cache: %d", cache.size());
- PRINTF("Polygons in cache: %d", cache.totalCost());
-}
contact: Jan Huwald // Impressum