summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Groff <arcata@gmail.com>2013-01-14 19:24:15 +0000
committerJoe Groff <arcata@gmail.com>2013-01-14 19:24:15 +0000
commitd3fc142fdd15c697770941833b6476c353237832 (patch)
tree41544b3d0da821bd9e32083ba0a88c22900ed9d6
parente9145d38466e3cf492295fa682f87f54c9b4ac0c (diff)
downloadbcm5719-llvm-d3fc142fdd15c697770941833b6476c353237832.tar.gz
bcm5719-llvm-d3fc142fdd15c697770941833b6476c353237832.zip
Add DenseMap::insert(value_type&&) method.
Use the existing move implementation of the internal DenseMap::InsertIntoBucket method to provide a user-facing move insert method. llvm-svn: 172453
-rw-r--r--llvm/include/llvm/ADT/DenseMap.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index 01f7e90c212..04912c703ca 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -159,6 +159,24 @@ public:
return std::make_pair(iterator(TheBucket, getBucketsEnd(), true), true);
}
+#ifdef LLVM_HAS_RVALUE_REFERENCES
+ // Inserts key,value pair into the map if the key isn't already in the map.
+ // If the key is already in the map, it returns false and doesn't update the
+ // value.
+ std::pair<iterator, bool> insert(std::pair<KeyT, ValueT> &&KV) {
+ BucketT *TheBucket;
+ if (LookupBucketFor(KV.first, TheBucket))
+ return std::make_pair(iterator(TheBucket, getBucketsEnd(), true),
+ false); // Already in map.
+
+ // Otherwise, insert the new element.
+ TheBucket = InsertIntoBucket(std::move(KV.first),
+ std::move(KV.second),
+ TheBucket);
+ return std::make_pair(iterator(TheBucket, getBucketsEnd(), true), true);
+ }
+#endif
+
/// insert - Range insertion of pairs.
template<typename InputIt>
void insert(InputIt I, InputIt E) {
OpenPOWER on IntegriCloud