================ @@ -70,16 +93,37 @@ class ParentMapContext::ParentMap { push_back(Value); } bool contains(const DynTypedNode &Value) { - return Seen.contains(Value); + assert(Value.getMemoizationData()); + bool found = FragileLazySeenCache.contains(&Value); + while (!found && ItemsProcessed < Items.size()) { + found |= FragileLazySeenCache.insert(&Items[ItemsProcessed]).second; + ++ItemsProcessed; + } + return found; } void push_back(const DynTypedNode &Value) { - if (!Value.getMemoizationData() || Seen.insert(Value).second) + if (!Value.getMemoizationData() || !contains(Value)) { + const size_t OldCapacity = Items.capacity(); Items.push_back(Value); + if (OldCapacity != Items.capacity()) { + // Pointers are invalidated; remove them. + ItemsProcessed = 0; + // Free memory to avoid doubling peak memory usage during rehashing + FragileLazySeenCache.clear(); + } + } } llvm::ArrayRef<DynTypedNode> view() const { return Items; } private: + // BE CAREFUL. Pointers into this container are stored in the cache. ---------------- erichkeane wrote:
```suggestion // BE CAREFUL. Pointers into this container are stored in the `FragileLazySeenCache` set below. ``` https://github.com/llvm/llvm-project/pull/129934 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits