From a4e5109183ea6c1b5d69f6b951691c09ad98cb27 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Mon, 25 Aug 2025 10:25:43 -0700 Subject: [PATCH] [ADT] Inline InsertIntoBucket and InsertIntoBucketWithLookup into their callers (NFC) InsertIntoBucket and InsertIntoBucketWithLookup each has exactly one caller. This patch inlines them into their respective sole callers, reducing the line count. While we are at it, this patch renames InsertIntoBucketImpl to findBucketForInsertion to better reflect its purpose now that InsertIntoBucket is being removed. --- llvm/include/llvm/ADT/DenseMap.h | 33 ++++++++------------------------ 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h index 2dfd1dabd07f1..c44706a597fa6 100644 --- a/llvm/include/llvm/ADT/DenseMap.h +++ b/llvm/include/llvm/ADT/DenseMap.h @@ -279,8 +279,9 @@ class DenseMapBase : public DebugEpochBase { return {makeInsertIterator(TheBucket), false}; // Already in map. // Otherwise, insert the new element. - TheBucket = InsertIntoBucketWithLookup(TheBucket, std::move(KV.first), - std::move(KV.second), Val); + TheBucket = findBucketForInsertion(Val, TheBucket); + TheBucket->getFirst() = std::move(KV.first); + ::new (&TheBucket->getSecond()) ValueT(std::move(KV.second)); return {makeInsertIterator(TheBucket), true}; } @@ -482,8 +483,9 @@ class DenseMapBase : public DebugEpochBase { return {makeInsertIterator(TheBucket), false}; // Already in the map. // Otherwise, insert the new element. - TheBucket = InsertIntoBucket(TheBucket, std::forward(Key), - std::forward(Args)...); + TheBucket = findBucketForInsertion(Key, TheBucket); + TheBucket->getFirst() = std::forward(Key); + ::new (&TheBucket->getSecond()) ValueT(std::forward(Args)...); return {makeInsertIterator(TheBucket), true}; } @@ -561,28 +563,9 @@ class DenseMapBase : public DebugEpochBase { void shrink_and_clear() { static_cast(this)->shrink_and_clear(); } - template - BucketT *InsertIntoBucket(BucketT *TheBucket, KeyArg &&Key, - ValueArgs &&...Values) { - TheBucket = InsertIntoBucketImpl(Key, TheBucket); - - TheBucket->getFirst() = std::forward(Key); - ::new (&TheBucket->getSecond()) ValueT(std::forward(Values)...); - return TheBucket; - } - - template - BucketT *InsertIntoBucketWithLookup(BucketT *TheBucket, KeyT &&Key, - ValueT &&Value, LookupKeyT &Lookup) { - TheBucket = InsertIntoBucketImpl(Lookup, TheBucket); - - TheBucket->getFirst() = std::move(Key); - ::new (&TheBucket->getSecond()) ValueT(std::move(Value)); - return TheBucket; - } - template - BucketT *InsertIntoBucketImpl(const LookupKeyT &Lookup, BucketT *TheBucket) { + BucketT *findBucketForInsertion(const LookupKeyT &Lookup, + BucketT *TheBucket) { incrementEpoch(); // If the load of the hash table is more than 3/4, or if fewer than 1/8 of