File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments