From: Benjamin Kramer <benny.kra@googlemail.com>
Date: Fri, 10 Apr 2015 12:46:44 +0000 (+0000)
Subject: Microoptimize DenseMap::clear.
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c8eb88e7448cb88d2edf31806a04ae9d44d6a66a;p=oota-llvm.git

Microoptimize DenseMap::clear.

Cache NumEntries locally, it's only used in an assert and using the member
variable prevents the compiler from eliminating the tombstone check for types
with trivial destructors. No functionality change intended.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234589 91177308-0d34-0410-b5e6-96231b3b80d8
---

diff --git a/include/llvm/ADT/DenseMap.h b/include/llvm/ADT/DenseMap.h
index 7bfa8b22f7a..9c2365af6eb 100644
--- a/include/llvm/ADT/DenseMap.h
+++ b/include/llvm/ADT/DenseMap.h
@@ -100,16 +100,18 @@ public:
     }
 
     const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey();
+    unsigned NumEntries = getNumEntries();
     for (BucketT *P = getBuckets(), *E = getBucketsEnd(); P != E; ++P) {
       if (!KeyInfoT::isEqual(P->getFirst(), EmptyKey)) {
         if (!KeyInfoT::isEqual(P->getFirst(), TombstoneKey)) {
           P->getSecond().~ValueT();
-          decrementNumEntries();
+          --NumEntries;
         }
         P->getFirst() = EmptyKey;
       }
     }
-    assert(getNumEntries() == 0 && "Node count imbalance!");
+    assert(NumEntries == 0 && "Node count imbalance!");
+    setNumEntries(0);
     setNumTombstones(0);
   }
 
@@ -257,7 +259,7 @@ public:
   const void *getPointerIntoBucketsArray() const { return getBuckets(); }
 
 protected:
-  DenseMapBase() {}
+  DenseMapBase() = default;
 
   void destroyAll() {
     if (getNumBuckets() == 0) // Nothing to do.