From d06252d48a7aa284b98a683488d6f4fcd3787f71 Mon Sep 17 00:00:00 2001 From: Andres Noetzli Date: Tue, 15 Mar 2022 09:07:44 -0700 Subject: [PATCH] Simplify `Scope` (#8307) Previously, we were using an std::unique_ptr> to store the list of ContextObjs to be garbage collected before the destruction of the Scope. Lazily allocating that vector is a micro-optimization that is not worth the trouble. --- src/context/context.cpp | 14 ++++---------- src/context/context.h | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/context/context.cpp b/src/context/context.cpp index 7e49b49ab..71f77f3ae 100644 --- a/src/context/context.cpp +++ b/src/context/context.cpp @@ -370,20 +370,14 @@ Scope::~Scope() { d_pContextObjList = d_pContextObjList->restoreAndContinue(); } - if (d_garbage) { - while (!d_garbage->empty()) { - ContextObj* obj = d_garbage->back(); - d_garbage->pop_back(); - obj->deleteSelf(); - } + for (ContextObj* obj : d_garbage) + { + obj->deleteSelf(); } } void Scope::enqueueToGarbageCollect(ContextObj* obj) { - if (!d_garbage) { - d_garbage.reset(new std::vector); - } - d_garbage->push_back(obj); + d_garbage.push_back(obj); } } // namespace context diff --git a/src/context/context.h b/src/context/context.h index 7dad00ded..e0f3f88e3 100644 --- a/src/context/context.h +++ b/src/context/context.h @@ -257,7 +257,7 @@ class Scope { * * This is either nullptr or list owned by this scope. */ - std::unique_ptr> d_garbage; + std::vector d_garbage; friend std::ostream& operator<<(std::ostream&, const Scope&); -- 2.30.2