[llvm] [ADT] Remove the const variant of LookupBucketFor in DenseMap (PR #107608)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 6 10:03:29 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/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.
>From 6c9b1cf684e37456862e35040877ef2e1141bbd5 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 6 Sep 2024 08:06:40 -0700
Subject: [PATCH] [ADT] Remove the const variant of LookupBucketFor in DenseMap
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.
---
llvm/include/llvm/ADT/DenseMap.h | 20 +++++---------------
1 file changed, 5 insertions(+), 15 deletions(-)
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.
More information about the llvm-commits
mailing list