]> granicus.if.org Git - graphviz/commitdiff
remove unnecessary temporary vector in Blocks::cleanup
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 12 Jun 2021 19:49:18 +0000 (12:49 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 19 Jun 2021 19:24:07 +0000 (12:24 -0700)
This code was taking a copy of every element in a set in order to iterate
through them while removing elements from the underlying set. However, this is
not necessary. This change replaces this code with the standard pattern for
deleting elements while iterating over a set.

lib/vpsc/blocks.cpp

index e6f99bfa4bd85b0aaa553235f6df518d936e47c4..a02c22f74b0d9d195c199a65637e3825ba14038d 100644 (file)
@@ -26,7 +26,6 @@
 using std::ios;
 using std::ofstream;
 using std::set;
-using std::vector;
 using std::list;
 
 #ifndef RECTANGLE_OVERLAP_LOGGING
@@ -156,12 +155,13 @@ void Blocks::removeBlock(Block *doomed) {
        //erase(doomed);
 }
 void Blocks::cleanup() {
-       vector<Block*> b_copy(begin(),end());
-       for(vector<Block*>::iterator i=b_copy.begin();i!=b_copy.end();i++) {
+       for (auto i = begin(); i != end();) {
                Block *b=*i;
                if(b->deleted) {
-                       erase(b);
+                       i = erase(i);
                        delete b;
+               } else {
+                       ++i;
                }
        }
 }