Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 13 additions & 33 deletions llvm/include/llvm/ADT/DenseMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,22 +257,13 @@ class DenseMapBase : public DebugEpochBase {
std::pair<iterator, bool> try_emplace(KeyT &&Key, Ts &&...Args) {
BucketT *TheBucket;
if (LookupBucketFor(Key, TheBucket))
return std::make_pair(makeIterator(TheBucket,
shouldReverseIterate<KeyT>()
? getBuckets()
: getBucketsEnd(),
*this, true),
return std::make_pair(makeInsertIterator(TheBucket),
false); // Already in map.

// Otherwise, insert the new element.
TheBucket =
InsertIntoBucket(TheBucket, std::move(Key), std::forward<Ts>(Args)...);
return std::make_pair(makeIterator(TheBucket,
shouldReverseIterate<KeyT>()
? getBuckets()
: getBucketsEnd(),
*this, true),
true);
return std::make_pair(makeInsertIterator(TheBucket), true);
}

// Inserts key,value pair into the map if the key isn't already in the map.
Expand All @@ -282,21 +273,12 @@ class DenseMapBase : public DebugEpochBase {
std::pair<iterator, bool> try_emplace(const KeyT &Key, Ts &&...Args) {
BucketT *TheBucket;
if (LookupBucketFor(Key, TheBucket))
return std::make_pair(makeIterator(TheBucket,
shouldReverseIterate<KeyT>()
? getBuckets()
: getBucketsEnd(),
*this, true),
return std::make_pair(makeInsertIterator(TheBucket),
false); // Already in map.

// Otherwise, insert the new element.
TheBucket = InsertIntoBucket(TheBucket, Key, std::forward<Ts>(Args)...);
return std::make_pair(makeIterator(TheBucket,
shouldReverseIterate<KeyT>()
? getBuckets()
: getBucketsEnd(),
*this, true),
true);
return std::make_pair(makeInsertIterator(TheBucket), true);
}

/// Alternate version of insert() which allows a different, and possibly
Expand All @@ -309,22 +291,13 @@ class DenseMapBase : public DebugEpochBase {
const LookupKeyT &Val) {
BucketT *TheBucket;
if (LookupBucketFor(Val, TheBucket))
return std::make_pair(makeIterator(TheBucket,
shouldReverseIterate<KeyT>()
? getBuckets()
: getBucketsEnd(),
*this, true),
return std::make_pair(makeInsertIterator(TheBucket),
false); // Already in map.

// Otherwise, insert the new element.
TheBucket = InsertIntoBucketWithLookup(TheBucket, std::move(KV.first),
std::move(KV.second), Val);
return std::make_pair(makeIterator(TheBucket,
shouldReverseIterate<KeyT>()
? getBuckets()
: getBucketsEnd(),
*this, true),
true);
return std::make_pair(makeInsertIterator(TheBucket), true);
}

/// insert - Range insertion of pairs.
Expand Down Expand Up @@ -545,6 +518,13 @@ class DenseMapBase : public DebugEpochBase {
return const_iterator(P, E, Epoch, NoAdvance);
}

iterator makeInsertIterator(BucketT *TheBucket) {
return makeIterator(TheBucket,
shouldReverseIterate<KeyT>() ? getBuckets()
: getBucketsEnd(),
*this, true);
}

unsigned getNumEntries() const {
return static_cast<const DerivedT *>(this)->getNumEntries();
}
Expand Down
Loading