Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Unified Diff: mojo/public/cpp/bindings/lib/map_internal.h

Issue 646773005: mojo: Switch the clipboard interface over to using map<>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: vtl nits + operator[] Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/map.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698