[llvm] [ADT] Deprecate DenseMap::FindAndConstruct (PR #107224)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 4 04:32:07 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/107224
I've migrated all uses of FindAndConstruct to operator[] and
try_emplace. This patch inlines FindAndConstruct into operator[] and
deprecates FindAndConstruct.
>From 211295aaddebb0f584fb6dcc8445dc885b54168b Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 2 Sep 2024 19:44:06 -0700
Subject: [PATCH] [ADT] Deprecate DenseMap::FindAndConstruct
I've migrated all uses of FindAndConstruct to operator[] and
try_emplace. This patch inlines FindAndConstruct into operator[] and
deprecates FindAndConstruct.
---
llvm/include/llvm/ADT/DenseMap.h | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index e78700f9a9f3ac..745288ff047f4a 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -354,7 +354,8 @@ class DenseMapBase : public DebugEpochBase {
incrementNumTombstones();
}
- value_type& FindAndConstruct(const KeyT &Key) {
+ LLVM_DEPRECATED("Use [Key] instead", "[Key]")
+ value_type &FindAndConstruct(const KeyT &Key) {
BucketT *TheBucket;
if (LookupBucketFor(Key, TheBucket))
return *TheBucket;
@@ -363,10 +364,15 @@ class DenseMapBase : public DebugEpochBase {
}
ValueT &operator[](const KeyT &Key) {
- return FindAndConstruct(Key).second;
+ BucketT *TheBucket;
+ if (LookupBucketFor(Key, TheBucket))
+ return TheBucket->second;
+
+ return InsertIntoBucket(TheBucket, Key)->second;
}
- value_type& FindAndConstruct(KeyT &&Key) {
+ LLVM_DEPRECATED("Use [Key] instead", "[Key]")
+ value_type &FindAndConstruct(KeyT &&Key) {
BucketT *TheBucket;
if (LookupBucketFor(Key, TheBucket))
return *TheBucket;
@@ -375,7 +381,11 @@ class DenseMapBase : public DebugEpochBase {
}
ValueT &operator[](KeyT &&Key) {
- return FindAndConstruct(std::move(Key)).second;
+ BucketT *TheBucket;
+ if (LookupBucketFor(Key, TheBucket))
+ return TheBucket->second;
+
+ return InsertIntoBucket(TheBucket, std::move(Key))->second;
}
/// isPointerIntoBucketsArray - Return true if the specified pointer points
More information about the llvm-commits
mailing list