Change DenseMap to use a power of 2 growth if one is given instead of the next power...
authorPete Cooper <peter_cooper@apple.com>
Tue, 23 Oct 2012 19:34:36 +0000 (19:34 +0000)
committerPete Cooper <peter_cooper@apple.com>
Tue, 23 Oct 2012 19:34:36 +0000 (19:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166493 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/DenseMap.h

index 0ae54f429267efe72022bc99742f764689335da4..ce07f8e9c5243b213684931b6486886b28be42d3 100644 (file)
@@ -420,7 +420,7 @@ private:
       NumBuckets = getNumBuckets();
     }
     if (NumBuckets-(NewNumEntries+getNumTombstones()) <= NumBuckets/8) {
-      this->grow(NumBuckets);
+      this->grow(NumBuckets * 2);
       LookupBucketFor(Key, TheBucket);
     }
     assert(TheBucket);
@@ -600,7 +600,8 @@ public:
     unsigned OldNumBuckets = NumBuckets;
     BucketT *OldBuckets = Buckets;
 
-    allocateBuckets(std::max<unsigned>(64, NextPowerOf2(AtLeast)));
+    AtLeast = isPowerOf2_32(AtLeast) ? AtLeast : NextPowerOf2(AtLeast);
+    allocateBuckets(std::max<unsigned>(64, AtLeast));
     assert(Buckets);
     if (!OldBuckets) {
       this->BaseT::initEmpty();
@@ -826,8 +827,10 @@ public:
   }
 
   void grow(unsigned AtLeast) {
-    if (AtLeast >= InlineBuckets)
-      AtLeast = std::max<unsigned>(64, NextPowerOf2(AtLeast));
+    if (AtLeast >= InlineBuckets) {
+      AtLeast = isPowerOf2_32(AtLeast) ? AtLeast : NextPowerOf2(AtLeast);
+      AtLeast = std::max<unsigned>(64, AtLeast);
+    }
 
     if (Small) {
       if (AtLeast < InlineBuckets)