From: Andres Noetzli Date: Tue, 15 Mar 2022 16:07:44 +0000 (-0700) Subject: Simplify `Scope` (#8307) X-Git-Tag: cvc5-1.0.0~257 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d06252d48a7aa284b98a683488d6f4fcd3787f71;p=cvc5.git 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. --- 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&);