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

Unified Diff: base/id_map.h

Issue 2496653002: Part 2 of base::IDMap refactor to eliminate IDMapOwnPointer/IDMapExternalPointer modes (Closed)
Patch Set: typedefs => using statements, update comments in base/id_map.h Created 4 years 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 | « android_webview/native/aw_contents_client_bridge.cc ('k') | base/id_map_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/id_map.h
diff --git a/base/id_map.h b/base/id_map.h
index 74fb8d0b596cb7e1b0d758ad4e8ddfc3eb2b0103..8545de84084fc7c116132051754d4222f130c3e8 100644
--- a/base/id_map.h
+++ b/base/id_map.h
@@ -17,18 +17,6 @@
#include "base/macros.h"
#include "base/sequence_checker.h"
-// Ownership semantics:
-// - OwnPointer means we store a unique_ptr that owns the object (so the
-// object is deleted in Remove() and during destruction).
-// - ExternalPointer means we store a raw pointer and don't own the object
-
-// TODO (http://crbug.com/647091): eliminate this enum, replace OwnPointer
-// mode in callsites with IDMap<unique_ptr<T>>
-enum IDMapOwnershipSemantics {
- IDMapExternalPointer,
- IDMapOwnPointer
-};
-
// This object maintains a list of IDs that can be quickly converted to
// pointers to objects. It is implemented as a hash table, optimized for
// relatively small data sets (in the common case, there will be exactly one
@@ -37,19 +25,16 @@ enum IDMapOwnershipSemantics {
// Items can be inserted into the container with arbitrary ID, but the caller
// must ensure they are unique. Inserting IDs and relying on automatically
// generated ones is not allowed because they can collide.
-//
-// This class does not have a virtual destructor, do not inherit from it when
-// ownership semantics are set to own because pointers will leak.
-template <typename T,
- IDMapOwnershipSemantics OS = IDMapExternalPointer,
- typename K = int32_t>
-class IDMap {
+
+// The map's value type (the V param) can be any dereferenceable type, such as a
+// raw pointer or smart pointer
+template <typename V, typename K = int32_t>
+class IDMap final {
public:
using KeyType = K;
private:
- using V = typename std::
- conditional<OS == IDMapExternalPointer, T*, std::unique_ptr<T>>::type;
+ using T = typename std::remove_reference<decltype(*V())>::type;
using HashTable = base::hash_map<KeyType, V>;
public:
@@ -149,9 +134,7 @@ class IDMap {
template<class ReturnType>
class Iterator {
public:
- Iterator(IDMap<T, OS, K>* map)
- : map_(map),
- iter_(map_->data_.begin()) {
+ Iterator(IDMap<V, K>* map) : map_(map), iter_(map_->data_.begin()) {
Init();
}
@@ -215,7 +198,7 @@ class IDMap {
}
}
- IDMap<T, OS, K>* map_;
+ IDMap<V, K>* map_;
typename HashTable::const_iterator iter_;
};
« no previous file with comments | « android_webview/native/aw_contents_client_bridge.cc ('k') | base/id_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698