Index: mojo/public/cpp/bindings/lib/map_internal.h |
diff --git a/mojo/public/cpp/bindings/lib/map_internal.h b/mojo/public/cpp/bindings/lib/map_internal.h |
index aa0fe7ee4218fe71c459ebd23a4cebac18c62650..f006cd011ae86033a2c5c56e9864eb70b55da23b 100644 |
--- a/mojo/public/cpp/bindings/lib/map_internal.h |
+++ b/mojo/public/cpp/bindings/lib/map_internal.h |
@@ -57,7 +57,7 @@ struct MapTraits<Key, Value, false> { |
static inline ValueRefType at(std::map<KeyStorageType, ValueStorageType>* m, |
KeyForwardType key) { |
// We don't have C++11 library support yet, so we have to emulate the crash |
- // on a non-existant key. |
+ // on a non-existent key. |
auto it = m->find(key); |
MOJO_CHECK(it != m->end()); |
return it->second; |
@@ -66,11 +66,17 @@ struct MapTraits<Key, Value, false> { |
const std::map<KeyStorageType, ValueStorageType>* m, |
KeyForwardType key) { |
// We don't have C++11 library support yet, so we have to emulate the crash |
- // on a non-existant key. |
+ // on a non-existent key. |
auto it = m->find(key); |
MOJO_CHECK(it != m->end()); |
return it->second; |
} |
+ static inline ValueRefType GetOrInsert( |
+ std::map<KeyStorageType, ValueStorageType>* m, |
+ KeyForwardType key) { |
+ // This is the backing for the index operator (operator[]). |
+ return (*m)[key]; |
+ } |
static inline void Insert(std::map<KeyStorageType, ValueStorageType>* m, |
KeyForwardType key, |
ValueForwardType value) { |
@@ -146,7 +152,7 @@ struct MapTraits<Key, Value, true> { |
static inline ValueRefType at(std::map<KeyStorageType, ValueStorageType>* m, |
KeyForwardType key) { |
// We don't have C++11 library support yet, so we have to emulate the crash |
- // on a non-existant key. |
+ // on a non-existent key. |
auto it = m->find(key); |
MOJO_CHECK(it != m->end()); |
return GetValue(it); |
@@ -155,11 +161,23 @@ struct MapTraits<Key, Value, true> { |
const std::map<KeyStorageType, ValueStorageType>* m, |
KeyForwardType key) { |
// We don't have C++11 library support yet, so we have to emulate the crash |
- // on a non-existant key. |
+ // on a non-existent key. |
auto it = m->find(key); |
MOJO_CHECK(it != m->end()); |
return GetValue(it); |
} |
+ static inline ValueRefType GetOrInsert( |
+ std::map<KeyStorageType, ValueStorageType>* m, |
+ KeyForwardType key) { |
+ // This is the backing for the index operator (operator[]). |
+ auto it = m->find(key); |
+ if (it == m->end()) { |
+ it = m->insert(std::make_pair(key, ValueStorageType())).first; |
+ new (it->second.buf) Value(); |
+ } |
+ |
+ return GetValue(it); |
+ } |
static inline void Insert(std::map<KeyStorageType, ValueStorageType>* m, |
KeyForwardType key, |
ValueRefType value) { |