Skip to content

Commit 0aab466

Browse files
committed
s [skip ci]
1 parent 6320972 commit 0aab466

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

lib/programmemory.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,27 @@ void ProgramMemory::erase_if(const std::function<bool(const ExprIdToken&)>& pred
173173
if (mValues->empty())
174174
return;
175175

176-
// TODO: messes with the use count
177-
const auto values = mValues;
176+
if (mValues.use_count() == 1)
177+
{
178+
// we are the only user so can use it directly
179+
for (auto it = mValues->begin(); it != mValues->end();) {
180+
if (pred(it->first))
181+
it = mValues->erase(it);
182+
else
183+
++it;
184+
}
185+
}
186+
else
187+
{
188+
const auto values = mValues;
178189

179-
for (auto it = values->begin(); it != values->end(); ++it) {
180-
if (!pred(it->first))
181-
continue;
190+
for (auto it = values->begin(); it != values->end(); ++it) {
191+
if (!pred(it->first))
192+
continue;
182193

183-
copyOnWrite();
184-
mValues->erase(it->first);
194+
copyOnWrite();
195+
mValues->erase(it->first);
196+
}
185197
}
186198
}
187199

0 commit comments

Comments
 (0)