[llvm] 85ab209 - [ADT] Inline InsertIntoBucket and InsertIntoBucketWithLookup into their callers (NFC) (#155550)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 27 08:28:27 PDT 2025
Author: Kazu Hirata
Date: 2025-08-27T08:28:23-07:00
New Revision: 85ab209e3b4d13b1e7e454412a98511459397635
URL: https://github.com/llvm/llvm-project/commit/85ab209e3b4d13b1e7e454412a98511459397635
DIFF: https://github.com/llvm/llvm-project/commit/85ab209e3b4d13b1e7e454412a98511459397635.diff
LOG: [ADT] Inline InsertIntoBucket and InsertIntoBucketWithLookup into their callers (NFC) (#155550)
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.
Added:
Modified:
llvm/include/llvm/ADT/DenseMap.h
Removed:
################################################################################
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<KeyArgT>(Key),
- std::forward<Ts>(Args)...);
+ TheBucket = findBucketForInsertion(Key, TheBucket);
+ TheBucket->getFirst() = std::forward<KeyArgT>(Key);
+ ::new (&TheBucket->getSecond()) ValueT(std::forward<Ts>(Args)...);
return {makeInsertIterator(TheBucket), true};
}
@@ -561,28 +563,9 @@ class DenseMapBase : public DebugEpochBase {
void shrink_and_clear() { static_cast<DerivedT *>(this)->shrink_and_clear(); }
- template <typename KeyArg, typename... ValueArgs>
- BucketT *InsertIntoBucket(BucketT *TheBucket, KeyArg &&Key,
- ValueArgs &&...Values) {
- TheBucket = InsertIntoBucketImpl(Key, TheBucket);
-
- TheBucket->getFirst() = std::forward<KeyArg>(Key);
- ::new (&TheBucket->getSecond()) ValueT(std::forward<ValueArgs>(Values)...);
- return TheBucket;
- }
-
- template <typename LookupKeyT>
- 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 <typename LookupKeyT>
- 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
More information about the llvm-commits
mailing list