Skip to content

Commit

Permalink
[LVI] Remove count/erase idiom in favor of checking result value of e…
Browse files Browse the repository at this point in the history
…rase

Minor compile time win.  Avoids an additional O(N) scan in the case where we are removing an element and costs nothing when we aren't.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290768 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
preames committed Dec 30, 2016
1 parent f4ae367 commit ef2b74a
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/Analysis/LazyValueInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,7 @@ void LazyValueInfoCache::eraseValue(Value *V) {
SmallVector<AssertingVH<BasicBlock>, 4> ToErase;
for (auto &I : OverDefinedCache) {
SmallPtrSetImpl<Value *> &ValueSet = I.second;
if (ValueSet.count(V))
ValueSet.erase(V);
ValueSet.erase(V);
if (ValueSet.empty())
ToErase.push_back(I.first);
}
Expand Down Expand Up @@ -533,12 +532,9 @@ void LazyValueInfoCache::threadEdgeImpl(BasicBlock *OldSucc,

bool changed = false;
for (Value *V : ValsToClear) {
// TODO: count and erase can be converted to a find/erase(itr) pattern
if (!ValueSet.count(V))
if (!ValueSet.erase(V))
continue;

ValueSet.erase(V);

// If we removed anything, then we potentially need to update
// blocks successors too.
changed = true;
Expand Down

0 comments on commit ef2b74a

Please sign in to comment.