Skip to content

Commit 124f5bc

Browse files
committed
Refs #10765: Improve performance on if/else chains
1 parent 901a331 commit 124f5bc

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

lib/programmemory.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ void ProgramMemory::erase_if(const std::function<bool(const ExprIdToken&)>& pred
194194
{
195195
if (mValues->empty())
196196
return;
197+
if (!hasModifiableVars)
198+
return;
197199

198200
// TODO: how to delay until we actuallly modify?
199201
copyOnWrite();
@@ -234,13 +236,15 @@ void ProgramMemory::replace(ProgramMemory pm, bool skipUnknown)
234236

235237
copyOnWrite();
236238

239+
hasModifiableVars = false;
237240
for (auto&& p : (*pm.mValues)) {
238241
if (skipUnknown) {
239242
auto it = mValues->find(p.first);
240243
if (it != mValues->end() && it->second.isUninitValue())
241244
continue;
242245
}
243246
(*mValues)[p.first] = std::move(p.second);
247+
hasModifiableVars |= p.first.tok->varId() > 0;
244248
}
245249
}
246250

lib/programmemory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ struct CPPCHECKLIB ProgramMemory {
158158
Map::iterator find(nonneg int exprid);
159159

160160
std::shared_ptr<Map> mValues;
161+
bool hasModifiableVars = false;
161162
};
162163

163164
struct ProgramMemoryState {

0 commit comments

Comments
 (0)