diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2012-07-03 07:16:13 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2012-07-03 07:16:13 +0000 |
commit | ce9a04132d1bf85967d6ad062d45dd75f148eef1 (patch) | |
tree | 91b73e863103ff4bf253790e42874e0a50384548 | |
parent | 1e59c78ab7d3205b390fc9b68db603d5ff3bf3a3 (diff) |
Micro-optimize this function a bit. This shrinks the generated code
some, and allows the routine to be inlined into common callers. The
various bits that hit this code in their hotpath seem slightly lower on
the profile, but I can't really measure a performance improvement as
everything seems to still be bottlenecked on likely cache misses. =/
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159648 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/ADT/DenseMap.h | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/include/llvm/ADT/DenseMap.h b/include/llvm/ADT/DenseMap.h index 783c0b4d9d..d502be65a7 100644 --- a/include/llvm/ADT/DenseMap.h +++ b/include/llvm/ADT/DenseMap.h @@ -442,11 +442,10 @@ private: template<typename LookupKeyT> 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,6 +486,7 @@ private: // Otherwise, it's a hash collision or a tombstone, continue quadratic // probing. BucketNo += ProbeAmt++; + BucketNo &= (NumBuckets-1); } } |