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

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: moar tests 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..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) {
« 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