X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FDenseMap.h;h=f60d688c0dced2e815cfc4083147695f089e4562;hb=a00b80b04c5edb08639c1c6b32e9231fd8b066f7;hp=045b5c6a442092a0f9193e56ec9cf9acf4c3f528;hpb=8dffa4a106b52d893388c94c24e365e14c468b7c;p=oota-llvm.git diff --git a/include/llvm/ADT/DenseMap.h b/include/llvm/ADT/DenseMap.h index 045b5c6a442..f60d688c0dc 100644 --- a/include/llvm/ADT/DenseMap.h +++ b/include/llvm/ADT/DenseMap.h @@ -442,11 +442,10 @@ private: template bool LookupBucketFor(const LookupKeyT &Val, const BucketT *&FoundBucket) const { - unsigned BucketNo = getHashValue(Val); - unsigned ProbeAmt = 1; const BucketT *BucketsPtr = getBuckets(); + const unsigned NumBuckets = getNumBuckets(); - if (getNumBuckets() == 0) { + if (NumBuckets == 0) { FoundBucket = 0; return false; } @@ -459,8 +458,10 @@ private: !KeyInfoT::isEqual(Val, TombstoneKey) && "Empty/Tombstone value shouldn't be inserted into map!"); + unsigned BucketNo = getHashValue(Val) & (NumBuckets-1); + unsigned ProbeAmt = 1; while (1) { - const BucketT *ThisBucket = BucketsPtr + (BucketNo & (getNumBuckets()-1)); + const BucketT *ThisBucket = BucketsPtr + BucketNo; // Found Val's bucket? If so, return it. if (KeyInfoT::isEqual(Val, ThisBucket->first)) { FoundBucket = ThisBucket; @@ -485,12 +486,13 @@ private: // Otherwise, it's a hash collision or a tombstone, continue quadratic // probing. BucketNo += ProbeAmt++; + BucketNo &= (NumBuckets-1); } } template bool LookupBucketFor(const LookupKeyT &Val, BucketT *&FoundBucket) { - const BucketT *ConstFoundBucket = FoundBucket; + const BucketT *ConstFoundBucket; bool Result = const_cast(this) ->LookupBucketFor(Val, ConstFoundBucket); FoundBucket = const_cast(ConstFoundBucket); @@ -615,8 +617,9 @@ public: this->destroyAll(); // Reduce the number of buckets. - unsigned NewNumBuckets - = std::max(64, 1 << (Log2_32_Ceil(OldNumEntries) + 1)); + unsigned NewNumBuckets = 0; + if (OldNumEntries) + NewNumBuckets = std::max(64, 1 << (Log2_32_Ceil(OldNumEntries) + 1)); if (NewNumBuckets == NumBuckets) { this->BaseT::initEmpty(); return; @@ -684,8 +687,7 @@ class SmallDenseMap /// A "union" of an inline bucket array and the struct representing /// a large bucket. This union will be discriminated by the 'Small' bit. - typename AlignedCharArray::union_type - storage; + AlignedCharArrayUnion storage; public: explicit SmallDenseMap(unsigned NumInitBuckets = 0) { @@ -831,8 +833,7 @@ public: return; // Nothing to do. // First move the inline buckets into a temporary storage. - typename AlignedCharArray::union_type - TmpStorage; + AlignedCharArrayUnion TmpStorage; BucketT *TmpBegin = reinterpret_cast(TmpStorage.buffer); BucketT *TmpEnd = TmpBegin; @@ -843,7 +844,7 @@ public: for (BucketT *P = getBuckets(), *E = P + InlineBuckets; P != E; ++P) { if (!KeyInfoT::isEqual(P->first, EmptyKey) && !KeyInfoT::isEqual(P->first, TombstoneKey)) { - assert((TmpEnd - TmpBegin) < InlineBuckets && + assert(size_t(TmpEnd - TmpBegin) < InlineBuckets && "Too many inline buckets!"); new (&TmpEnd->first) KeyT(llvm_move(P->first)); new (&TmpEnd->second) ValueT(llvm_move(P->second));