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