Skip to content

Commit

Permalink
s [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Aug 1, 2024
1 parent 6320972 commit 0aab466
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,27 @@ void ProgramMemory::erase_if(const std::function<bool(const ExprIdToken&)>& pred
if (mValues->empty())
return;

// TODO: messes with the use count
const auto values = mValues;
if (mValues.use_count() == 1)
{
// we are the only user so can use it directly
for (auto it = mValues->begin(); it != mValues->end();) {
if (pred(it->first))
it = mValues->erase(it);
else
++it;
}
}
else
{
const auto values = mValues;

for (auto it = values->begin(); it != values->end(); ++it) {
if (!pred(it->first))
continue;
for (auto it = values->begin(); it != values->end(); ++it) {
if (!pred(it->first))
continue;

copyOnWrite();
mValues->erase(it->first);
copyOnWrite();
mValues->erase(it->first);
}
}
}

Expand Down

0 comments on commit 0aab466

Please sign in to comment.