Index: base/id_map.h |
diff --git a/base/id_map.h b/base/id_map.h |
index 9cbc1f8978fa8836b770f8370ff3b2a3f44e2017..bb47892c1e47dd31a57f81718b3d04684c3e96fb 100644 |
--- a/base/id_map.h |
+++ b/base/id_map.h |
@@ -53,7 +53,8 @@ class IDMap : public base::NonThreadSafe { |
Releaser<OS, 0>::release_all(&data_); |
} |
- // Sets whether Add should CHECK if passed in NULL data. Default is false. |
+ // Sets whether Add and Replace should CHECK if passed in NULL data. |
+ // Default is false. |
void set_check_on_null_data(bool value) { check_on_null_data_ = value; } |
// Adds a view with an automatically generated unique ID. See AddWithID. |
@@ -94,6 +95,25 @@ class IDMap : public base::NonThreadSafe { |
} |
} |
+ // Replaces the value for |id| with |new_data| and returns a pointer to the |
+ // existing value. If there is no entry for |id|, the map is not altered and |
+ // nullptr is returned. The OwnershipSemantics of the map have no affect on |
rvargas (doing something else)
2014/12/06 00:37:03
nit: s/affect/effect
michaeln
2014/12/08 23:56:43
Done.
|
+ // how the existing value is treated, the IDMap does not delete the existing |
+ // value being replaced. |
+ T* Replace(KeyType id, T* new_data) { |
+ DCHECK(CalledOnValidThread()); |
+ CHECK(!check_on_null_data_ || new_data); |
rvargas (doing something else)
2014/12/06 00:37:03
Do you mind changing this (and the other instances
michaeln
2014/12/08 23:56:43
Done.
|
+ typename HashTable::iterator i = data_.find(id); |
+ if (i == data_.end()) { |
+ NOTREACHED() << "Attempting to replace an item not in the list"; |
+ return nullptr; |
+ } |
+ |
+ T* temp = i->second; |
+ i->second = new_data; |
+ return temp; |
+ } |
+ |
void Clear() { |
DCHECK(CalledOnValidThread()); |
if (iteration_depth_ == 0) { |