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

Unified Diff: components/policy/core/common/schema.cc

Issue 1096983002: Update usages of std::map to use ScopedPtrMap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@passwordmanager-scopedmemory
Patch Set: Rebase. Created 5 years, 6 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
Index: components/policy/core/common/schema.cc
diff --git a/components/policy/core/common/schema.cc b/components/policy/core/common/schema.cc
index 92244789629f37bcd72a32c30487980870d91c6f..84a1a3c999feb6d98febc8dabc953273f15ba8f6 100644
--- a/components/policy/core/common/schema.cc
+++ b/components/policy/core/common/schema.cc
@@ -10,10 +10,10 @@
#include <utility>
#include "base/compiler_specific.h"
+#include "base/containers/scoped_ptr_map.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
-#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "components/json_schema/json_schema_constants.h"
#include "components/json_schema/json_schema_validator.h"
@@ -247,8 +247,7 @@ class Schema::InternalStorage
// Cache for CompileRegex(), will memorize return value of every call to
// CompileRegex() and return results directly next time.
- mutable std::map<std::string, re2::RE2*> regex_cache_;
- STLValueDeleter<std::map<std::string, re2::RE2*> > regex_cache_deleter_;
+ mutable base::ScopedPtrMap<std::string, scoped_ptr<re2::RE2>> regex_cache_;
SchemaData schema_data_;
std::vector<std::string> strings_;
@@ -262,10 +261,11 @@ class Schema::InternalStorage
DISALLOW_COPY_AND_ASSIGN(InternalStorage);
};
-Schema::InternalStorage::InternalStorage()
- : regex_cache_deleter_(&regex_cache_) {}
+Schema::InternalStorage::InternalStorage() {
+}
-Schema::InternalStorage::~InternalStorage() {}
+Schema::InternalStorage::~InternalStorage() {
+}
// static
scoped_refptr<const Schema::InternalStorage> Schema::InternalStorage::Wrap(
@@ -342,11 +342,13 @@ Schema::InternalStorage::ParseSchema(const base::DictionaryValue& schema,
re2::RE2* Schema::InternalStorage::CompileRegex(
const std::string& pattern) const {
- std::map<std::string, re2::RE2*>::iterator it = regex_cache_.find(pattern);
+ base::ScopedPtrMap<std::string, scoped_ptr<re2::RE2>>::const_iterator it =
+ regex_cache_.find(pattern);
if (it == regex_cache_.end()) {
- re2::RE2* compiled = new re2::RE2(pattern);
- regex_cache_[pattern] = compiled;
- return compiled;
+ scoped_ptr<re2::RE2> compiled(new re2::RE2(pattern));
+ re2::RE2* compiled_ptr = compiled.get();
+ regex_cache_.insert(pattern, compiled.Pass());
+ return compiled_ptr;
}
return it->second;
}

Powered by Google App Engine
This is Rietveld 408576698