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..be885bc38636c03a3eed5b714d6b135d7df30464 100644 |
--- a/mojo/public/cpp/bindings/lib/map_internal.h |
+++ b/mojo/public/cpp/bindings/lib/map_internal.h |
@@ -71,6 +71,11 @@ struct MapTraits<Key, Value, false> { |
MOJO_CHECK(it != m->end()); |
return it->second; |
} |
+ static inline ValueRefType Index( |
viettrungluu
2014/10/15 23:17:23
Hmmm. I still find the name "Index" a bit perplexi
Elliot Glaysher
2014/10/15 23:30:44
Because it is the backing for the index operator.
|
+ std::map<KeyStorageType, ValueStorageType>* m, |
+ KeyForwardType key) { |
+ return (*m)[key]; |
+ } |
static inline void Insert(std::map<KeyStorageType, ValueStorageType>* m, |
KeyForwardType key, |
ValueForwardType value) { |
@@ -160,6 +165,17 @@ struct MapTraits<Key, Value, true> { |
MOJO_CHECK(it != m->end()); |
return GetValue(it); |
} |
+ static inline ValueRefType Index( |
+ std::map<KeyStorageType, ValueStorageType>* m, |
+ KeyForwardType key) { |
+ 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) { |