Skip to content

Commit c014db4

Browse files
[ADT] Remove the const variant of LookupBucketFor in DenseMap (#107608)
DenseMap has const and non-const variants of LookupBucketFor to find a bucket for insertion purposes. Now that queries (e.g. find, contains, and erase) have been migrated to use doFind instead of LookupBucketFor, nobody uses the const variant of LookupBucketFor. This patch removes the const variant. As far as the logistics go, the non-const variant calls the const variant with a couple of const_cast, so this patch repurposes the const variant as the non-const one while removing the original non-const variant.
1 parent 59f8796 commit c014db4

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

llvm/include/llvm/ADT/DenseMap.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,9 @@ class DenseMapBase : public DebugEpochBase {
678678
/// FoundBucket. If the bucket contains the key and a value, this returns
679679
/// true, otherwise it returns a bucket with an empty marker or tombstone and
680680
/// returns false.
681-
template<typename LookupKeyT>
682-
bool LookupBucketFor(const LookupKeyT &Val,
683-
const BucketT *&FoundBucket) const {
684-
const BucketT *BucketsPtr = getBuckets();
681+
template <typename LookupKeyT>
682+
bool LookupBucketFor(const LookupKeyT &Val, BucketT *&FoundBucket) {
683+
BucketT *BucketsPtr = getBuckets();
685684
const unsigned NumBuckets = getNumBuckets();
686685

687686
if (NumBuckets == 0) {
@@ -690,7 +689,7 @@ class DenseMapBase : public DebugEpochBase {
690689
}
691690

692691
// FoundTombstone - Keep track of whether we find a tombstone while probing.
693-
const BucketT *FoundTombstone = nullptr;
692+
BucketT *FoundTombstone = nullptr;
694693
const KeyT EmptyKey = getEmptyKey();
695694
const KeyT TombstoneKey = getTombstoneKey();
696695
assert(!KeyInfoT::isEqual(Val, EmptyKey) &&
@@ -700,7 +699,7 @@ class DenseMapBase : public DebugEpochBase {
700699
unsigned BucketNo = getHashValue(Val) & (NumBuckets-1);
701700
unsigned ProbeAmt = 1;
702701
while (true) {
703-
const BucketT *ThisBucket = BucketsPtr + BucketNo;
702+
BucketT *ThisBucket = BucketsPtr + BucketNo;
704703
// Found Val's bucket? If so, return it.
705704
if (LLVM_LIKELY(KeyInfoT::isEqual(Val, ThisBucket->getFirst()))) {
706705
FoundBucket = ThisBucket;
@@ -729,15 +728,6 @@ class DenseMapBase : public DebugEpochBase {
729728
}
730729
}
731730

732-
template <typename LookupKeyT>
733-
bool LookupBucketFor(const LookupKeyT &Val, BucketT *&FoundBucket) {
734-
const BucketT *ConstFoundBucket;
735-
bool Result = const_cast<const DenseMapBase *>(this)
736-
->LookupBucketFor(Val, ConstFoundBucket);
737-
FoundBucket = const_cast<BucketT *>(ConstFoundBucket);
738-
return Result;
739-
}
740-
741731
public:
742732
/// Return the approximate size (in bytes) of the actual map.
743733
/// This is just the raw memory used by DenseMap.

0 commit comments

Comments
 (0)