From 7cbe7c4a4151d7c46398cea01c26852247d77e6e Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 12 Jun 2021 12:49:18 -0700 Subject: [PATCH] remove unnecessary temporary vector in Blocks::cleanup 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 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/vpsc/blocks.cpp b/lib/vpsc/blocks.cpp index e6f99bfa4..a02c22f74 100644 --- a/lib/vpsc/blocks.cpp +++ b/lib/vpsc/blocks.cpp @@ -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 b_copy(begin(),end()); - for(vector::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; } } } -- 2.40.0