[llvm] bab468f - [llvm][ADT] Remove duplicate code in llvm::StringMapImpl::RehashTable
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 16 01:01:40 PDT 2022
Author: wangyihan
Date: 2022-03-16T01:01:35-07:00
New Revision: bab468f2536219ec824a2b6fe959fcaa7abf5685
URL: https://github.com/llvm/llvm-project/commit/bab468f2536219ec824a2b6fe959fcaa7abf5685
DIFF: https://github.com/llvm/llvm-project/commit/bab468f2536219ec824a2b6fe959fcaa7abf5685.diff
LOG: [llvm][ADT] Remove duplicate code in llvm::StringMapImpl::RehashTable
Remove duplicate code in llvm::StringMapImpl::RehashTable, near StringMap.cpp:229
```
if (!NewTableArray[NewBucket]) {
NewTableArray[FullHash & (NewSize - 1)] = Bucket;
NewHashArray[FullHash & (NewSize - 1)] = FullHash;
if (I == BucketNo)
NewBucketNo = NewBucket;
continue;
}
```
Reviewed By: MaskRay, dexonsmith
Differential Revision: https://reviews.llvm.org/D121726
Added:
Modified:
llvm/lib/Support/StringMap.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/StringMap.cpp b/llvm/lib/Support/StringMap.cpp
index 012c785b4351d..531376ae12a88 100644
--- a/llvm/lib/Support/StringMap.cpp
+++ b/llvm/lib/Support/StringMap.cpp
@@ -226,23 +226,16 @@ unsigned StringMapImpl::RehashTable(unsigned BucketNo) {
for (unsigned I = 0, E = NumBuckets; I != E; ++I) {
StringMapEntryBase *Bucket = TheTable[I];
if (Bucket && Bucket != getTombstoneVal()) {
- // Fast case, bucket available.
+ // If the bucket is not available, probe for a spot.
unsigned FullHash = HashTable[I];
unsigned NewBucket = FullHash & (NewSize - 1);
- if (!NewTableArray[NewBucket]) {
- NewTableArray[FullHash & (NewSize - 1)] = Bucket;
- NewHashArray[FullHash & (NewSize - 1)] = FullHash;
- if (I == BucketNo)
- NewBucketNo = NewBucket;
- continue;
+ if (NewTableArray[NewBucket]) {
+ unsigned ProbeSize = 1;
+ do {
+ NewBucket = (NewBucket + ProbeSize++) & (NewSize - 1);
+ } while (NewTableArray[NewBucket]);
}
- // Otherwise probe for a spot.
- unsigned ProbeSize = 1;
- do {
- NewBucket = (NewBucket + ProbeSize++) & (NewSize - 1);
- } while (NewTableArray[NewBucket]);
-
// Finally found a slot. Fill it in.
NewTableArray[NewBucket] = Bucket;
NewHashArray[NewBucket] = FullHash;
More information about the llvm-commits
mailing list