Chromium Code Reviews| Index: components/url_matcher/url_matcher.cc |
| diff --git a/components/url_matcher/url_matcher.cc b/components/url_matcher/url_matcher.cc |
| index 8e5cd9ebfdc7b16f982a4356ec10955981e3cc7f..2d4bc0559853b289c34c05045a505dd9e628ae37 100644 |
| --- a/components/url_matcher/url_matcher.cc |
| +++ b/components/url_matcher/url_matcher.cc |
| @@ -9,6 +9,7 @@ |
| #include <utility> |
| #include "base/logging.h" |
| +#include "base/memory/ptr_util.h" |
| #include "base/stl_util.h" |
| #include "url/gurl.h" |
| #include "url/url_canon.h" |
| @@ -262,9 +263,6 @@ const char kQuerySeparator = '&'; |
| URLMatcherConditionFactory::URLMatcherConditionFactory() : id_counter_(0) {} |
| URLMatcherConditionFactory::~URLMatcherConditionFactory() { |
| - base::STLDeleteElements(&substring_pattern_singletons_); |
| - base::STLDeleteElements(®ex_pattern_singletons_); |
| - base::STLDeleteElements(&origin_and_path_regex_pattern_singletons_); |
| } |
| std::string URLMatcherConditionFactory::CanonicalizeURLForComponentSearches( |
| @@ -463,32 +461,28 @@ URLMatcherConditionFactory::CreateOriginAndPathMatchesCondition( |
| void URLMatcherConditionFactory::ForgetUnusedPatterns( |
| const std::set<StringPattern::ID>& used_patterns) { |
| - PatternSingletons::iterator i = substring_pattern_singletons_.begin(); |
| + auto i = substring_pattern_singletons_.begin(); |
| while (i != substring_pattern_singletons_.end()) { |
| - if (base::ContainsKey(used_patterns, (*i)->id())) { |
| + if (base::ContainsKey(used_patterns, i->first->id())) |
| ++i; |
| - } else { |
| - delete *i; |
| + else |
| substring_pattern_singletons_.erase(i++); |
| - } |
| } |
| + |
| i = regex_pattern_singletons_.begin(); |
| while (i != regex_pattern_singletons_.end()) { |
| - if (base::ContainsKey(used_patterns, (*i)->id())) { |
| + if (base::ContainsKey(used_patterns, i->first->id())) |
| ++i; |
| - } else { |
| - delete *i; |
| + else |
| regex_pattern_singletons_.erase(i++); |
| - } |
| } |
| + |
| i = origin_and_path_regex_pattern_singletons_.begin(); |
| while (i != origin_and_path_regex_pattern_singletons_.end()) { |
| - if (base::ContainsKey(used_patterns, (*i)->id())) { |
| + if (base::ContainsKey(used_patterns, i->first->id())) |
| ++i; |
| - } else { |
| - delete *i; |
| + else |
| origin_and_path_regex_pattern_singletons_.erase(i++); |
| - } |
| } |
| } |
| @@ -501,7 +495,7 @@ bool URLMatcherConditionFactory::IsEmpty() const { |
| URLMatcherCondition URLMatcherConditionFactory::CreateCondition( |
| URLMatcherCondition::Criterion criterion, |
| const std::string& pattern) { |
| - StringPattern search_pattern(pattern, 0); |
| + StringPattern search_pattern(pattern, id_counter_++); |
|
battre
2016/10/24 11:32:16
why did you change this?
Avi (use Gerrit)
2016/10/24 14:38:06
Gah. It was a remnant of an earlier attempt to fix
|
| PatternSingletons* pattern_singletons = NULL; |
| if (IsRegexCriterion(criterion)) |
| pattern_singletons = ®ex_pattern_singletons_; |
| @@ -510,14 +504,13 @@ URLMatcherCondition URLMatcherConditionFactory::CreateCondition( |
| else |
| pattern_singletons = &substring_pattern_singletons_; |
| - PatternSingletons::const_iterator iter = |
| - pattern_singletons->find(&search_pattern); |
| + auto iter = pattern_singletons->find(&search_pattern); |
| if (iter != pattern_singletons->end()) |
| - return URLMatcherCondition(criterion, *iter); |
| + return URLMatcherCondition(criterion, iter->first); |
| StringPattern* new_pattern = new StringPattern(pattern, id_counter_++); |
| - pattern_singletons->insert(new_pattern); |
| + (*pattern_singletons)[new_pattern] = base::WrapUnique(new_pattern); |
| return URLMatcherCondition(criterion, new_pattern); |
| } |