diff --git a/src/db/db/dbCompoundOperation.cc b/src/db/db/dbCompoundOperation.cc index c26b82cd6..29f1a37dd 100644 --- a/src/db/db/dbCompoundOperation.cc +++ b/src/db/db/dbCompoundOperation.cc @@ -366,6 +366,7 @@ CompoundRegionMultiInputOperationNode::~CompoundRegionMultiInputOperationNode () void CompoundRegionMultiInputOperationNode::invalidate_cache () const { + CompoundRegionOperationNode::invalidate_cache (); for (tl::shared_collection::const_iterator i = m_children.begin (); i != m_children.end (); ++i) { i->invalidate_cache (); } diff --git a/src/db/db/dbCompoundOperation.h b/src/db/db/dbCompoundOperation.h index 1f8b13e27..0d0563704 100644 --- a/src/db/db/dbCompoundOperation.h +++ b/src/db/db/dbCompoundOperation.h @@ -222,6 +222,11 @@ public: m_cache_edge_pair_valid = false; } + void setup_cache () const + { + invalidate_cache (); + } + protected: // the different computation slots virtual void do_compute_local (db::Layout * /*layout*/, const shape_interactions & /*interactions*/, std::vector > & /*results*/, size_t /*max_vertex_count*/, double /*area_ratio*/) const { } @@ -255,14 +260,27 @@ private: template void implement_compute_local (db::Layout *layout, const shape_interactions &interactions, std::vector > &results, size_t max_vertex_count, double area_ratio) const { + // TODO: confine caching to those nodes which need it. + std::vector > *cache = 0; bool *valid = 0; get_cache (cache, valid); - if (*valid) { - results = *cache; - } else { - do_compute_local (layout, interactions, results, max_vertex_count, area_ratio); - *cache = results; + + if (! *valid) { + + std::vector > uncached_results; + uncached_results.resize (results.size ()); + + do_compute_local (layout, interactions, uncached_results, max_vertex_count, area_ratio); + + cache->swap (uncached_results); + *valid = true; + + } + + tl_assert (results.size () == cache->size ()); + for (size_t r = 0; r < results.size (); ++r) { + results[r].insert ((*cache)[r].begin (), (*cache)[r].end ()); } } }; @@ -1569,6 +1587,7 @@ public: protected: virtual void do_compute_local (db::Layout *layout, const shape_interactions &interactions, std::vector > &results, size_t max_vertex_count, double area_ratio) const { + mp_node->setup_cache (); mp_node->compute_local (layout, interactions, results, max_vertex_count, area_ratio); }