Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Sep 6, 2024

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/107608.diff

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/DenseMap.h (+5-15)
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index 745288ff047f4a..00290c9dd0a585 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -678,10 +678,9 @@ class DenseMapBase : public DebugEpochBase {
   /// FoundBucket.  If the bucket contains the key and a value, this returns
   /// true, otherwise it returns a bucket with an empty marker or tombstone and
   /// returns false.
-  template<typename LookupKeyT>
-  bool LookupBucketFor(const LookupKeyT &Val,
-                       const BucketT *&FoundBucket) const {
-    const BucketT *BucketsPtr = getBuckets();
+  template <typename LookupKeyT>
+  bool LookupBucketFor(const LookupKeyT &Val, BucketT *&FoundBucket) {
+    BucketT *BucketsPtr = getBuckets();
     const unsigned NumBuckets = getNumBuckets();
 
     if (NumBuckets == 0) {
@@ -690,7 +689,7 @@ class DenseMapBase : public DebugEpochBase {
     }
 
     // FoundTombstone - Keep track of whether we find a tombstone while probing.
-    const BucketT *FoundTombstone = nullptr;
+    BucketT *FoundTombstone = nullptr;
     const KeyT EmptyKey = getEmptyKey();
     const KeyT TombstoneKey = getTombstoneKey();
     assert(!KeyInfoT::isEqual(Val, EmptyKey) &&
@@ -700,7 +699,7 @@ class DenseMapBase : public DebugEpochBase {
     unsigned BucketNo = getHashValue(Val) & (NumBuckets-1);
     unsigned ProbeAmt = 1;
     while (true) {
-      const BucketT *ThisBucket = BucketsPtr + BucketNo;
+      BucketT *ThisBucket = BucketsPtr + BucketNo;
       // Found Val's bucket?  If so, return it.
       if (LLVM_LIKELY(KeyInfoT::isEqual(Val, ThisBucket->getFirst()))) {
         FoundBucket = ThisBucket;
@@ -729,15 +728,6 @@ class DenseMapBase : public DebugEpochBase {
     }
   }
 
-  template <typename LookupKeyT>
-  bool LookupBucketFor(const LookupKeyT &Val, BucketT *&FoundBucket) {
-    const BucketT *ConstFoundBucket;
-    bool Result = const_cast<const DenseMapBase *>(this)
-      ->LookupBucketFor(Val, ConstFoundBucket);
-    FoundBucket = const_cast<BucketT *>(ConstFoundBucket);
-    return Result;
-  }
-
 public:
   /// Return the approximate size (in bytes) of the actual map.
   /// This is just the raw memory used by DenseMap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants