Skip to content

Commit

Permalink
ProgramMemory: added some early outs
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Jul 29, 2024
1 parent 688a245 commit f4ecd32
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ ValueFlow::Value& ProgramMemory::at(nonneg int exprid) {

void ProgramMemory::erase_if(const std::function<bool(const ExprIdToken&)>& pred)
{
if (mValues->empty())
return;

// TODO: how to delay until we actuallly modify?
copyOnWrite();

Expand All @@ -188,6 +191,9 @@ void ProgramMemory::swap(ProgramMemory &pm)

void ProgramMemory::clear()
{
if (mValues->empty())
return;

copyOnWrite();

mValues->clear();
Expand All @@ -200,6 +206,9 @@ bool ProgramMemory::empty() const

void ProgramMemory::replace(ProgramMemory pm)
{
if (pm.empty())
return;

copyOnWrite();

for (auto&& p : (*pm.mValues)) {
Expand All @@ -209,6 +218,9 @@ void ProgramMemory::replace(ProgramMemory pm)

void ProgramMemory::insert(const ProgramMemory &pm)
{
if (pm.empty())
return;

copyOnWrite();

for (auto&& p : pm)
Expand Down

0 comments on commit f4ecd32

Please sign in to comment.