summaryrefslogtreecommitdiff
path: root/runtime/safe_map.h
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/safe_map.h')
-rw-r--r--runtime/safe_map.h16
1 files changed, 14 insertions, 2 deletions
diff --git a/runtime/safe_map.h b/runtime/safe_map.h
index 402c7e9cb5..7ac17b60d6 100644
--- a/runtime/safe_map.h
+++ b/runtime/safe_map.h
@@ -92,6 +92,11 @@ class SafeMap {
DCHECK(result.second); // Check we didn't accidentally overwrite an existing value.
return result.first;
}
+ iterator Put(const K& k, const V&& v) {
+ std::pair<iterator, bool> result = map_.emplace(k, std::move(v));
+ DCHECK(result.second); // Check we didn't accidentally overwrite an existing value.
+ return result.first;
+ }
// Used to insert a new mapping at a known position for better performance.
iterator PutBefore(iterator pos, const K& k, const V& v) {
@@ -100,16 +105,23 @@ class SafeMap {
DCHECK(pos == map_.begin() || map_.key_comp()((--iterator(pos))->first, k));
return map_.emplace_hint(pos, k, v);
}
+ iterator PutBefore(iterator pos, const K& k, const V&& v) {
+ // Check that we're using the correct position and the key is not in the map.
+ DCHECK(pos == map_.end() || map_.key_comp()(k, pos->first));
+ DCHECK(pos == map_.begin() || map_.key_comp()((--iterator(pos))->first, k));
+ return map_.emplace_hint(pos, k, std::move(v));
+ }
// Used to insert a new mapping or overwrite an existing mapping. Note that if the value type
// of this container is a pointer, any overwritten pointer will be lost and if this container
- // was the owner, you have a leak.
- void Overwrite(const K& k, const V& v) {
+ // was the owner, you have a leak. Returns iterator pointing to the new or overwritten entry.
+ iterator Overwrite(const K& k, const V& v) {
std::pair<iterator, bool> result = map_.insert(std::make_pair(k, v));
if (!result.second) {
// Already there - update the value for the existing key
result.first->second = v;
}
+ return result.first;
}
bool Equals(const Self& rhs) const {