We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
erase_if()
1 parent 53e55be commit 6320972Copy full SHA for 6320972
1 file changed
lib/programmemory.cpp
@@ -173,14 +173,15 @@ void ProgramMemory::erase_if(const std::function<bool(const ExprIdToken&)>& pred
173
if (mValues->empty())
174
return;
175
176
- // TODO: how to delay until we actuallly modify?
177
- copyOnWrite();
+ // TODO: messes with the use count
+ const auto values = mValues;
178
+
179
+ for (auto it = values->begin(); it != values->end(); ++it) {
180
+ if (!pred(it->first))
181
+ continue;
182
- for (auto it = mValues->begin(); it != mValues->end();) {
- if (pred(it->first))
- it = mValues->erase(it);
- else
183
- ++it;
+ copyOnWrite();
184
+ mValues->erase(it->first);
185
}
186
187
0 commit comments