Simplify `Scope` (#8307)
authorAndres Noetzli <andres.noetzli@gmail.com>
Tue, 15 Mar 2022 16:07:44 +0000 (09:07 -0700)
committerGitHub <noreply@github.com>
Tue, 15 Mar 2022 16:07:44 +0000 (11:07 -0500)
Previously, we were using an std::unique_ptr<std::vector<ContextObj*>>
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
src/context/context.h

index 7e49b49abf5e04d892a5fec5914469929bc2cfe9..71f77f3ae5a196d91c9c9c6c62abb306345f1c43 100644 (file)
@@ -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<ContextObj*>);
-  }
-  d_garbage->push_back(obj);
+  d_garbage.push_back(obj);
 }
 
 }  // namespace context
index 7dad00ded87820e88163da271d7463ee54a6aea1..e0f3f88e34ef46ec254d561710df768301dc283b 100644 (file)
@@ -257,7 +257,7 @@ class Scope {
    *
    * This is either nullptr or list owned by this scope.
    */
-  std::unique_ptr<std::vector<ContextObj*>> d_garbage;
+  std::vector<ContextObj*> d_garbage;
 
   friend std::ostream& operator<<(std::ostream&, const Scope&);