Skip to content

Commit

Permalink
Cleanup: AutofillRegexes use a ScopedPtrHashMap instead of a std::map.
Browse files Browse the repository at this point in the history
Review URL: https://codereview.chromium.org/818563002

Cr-Commit-Position: refs/heads/master@{#309124}
  • Loading branch information
leizleiz authored and Commit bot committed Dec 19, 2014
1 parent 58e3591 commit cbca971
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions components/autofill/core/browser/autofill_regexes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

#include "components/autofill/core/browser/autofill_regexes.h"

#include <map>
#include <utility>

#include "base/containers/scoped_ptr_hash_map.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "base/stl_util.h"
#include "base/strings/string16.h"
#include "third_party/icu/source/i18n/unicode/regex.h"

Expand All @@ -30,7 +27,7 @@ class AutofillRegexes {
friend struct DefaultSingletonTraits<AutofillRegexes>;

// Maps patterns to their corresponding regex matchers.
std::map<base::string16, icu::RegexMatcher*> matchers_;
base::ScopedPtrHashMap<base::string16, icu::RegexMatcher> matchers_;

DISALLOW_COPY_AND_ASSIGN(AutofillRegexes);
};
Expand All @@ -44,24 +41,23 @@ AutofillRegexes::AutofillRegexes() {
}

AutofillRegexes::~AutofillRegexes() {
STLDeleteContainerPairSecondPointers(matchers_.begin(),
matchers_.end());
}

icu::RegexMatcher* AutofillRegexes::GetMatcher(const base::string16& pattern) {
if (!matchers_.count(pattern)) {
auto it = matchers_.find(pattern);
if (it == matchers_.end()) {
const icu::UnicodeString icu_pattern(pattern.data(), pattern.length());

UErrorCode status = U_ZERO_ERROR;
icu::RegexMatcher* matcher = new icu::RegexMatcher(icu_pattern,
UREGEX_CASE_INSENSITIVE,
status);
scoped_ptr<icu::RegexMatcher> matcher(
new icu::RegexMatcher(icu_pattern, UREGEX_CASE_INSENSITIVE, status));
DCHECK(U_SUCCESS(status));

matchers_.insert(std::make_pair(pattern, matcher));
auto result = matchers_.add(pattern, matcher.Pass());
DCHECK(result.second);
it = result.first;
}

return matchers_[pattern];
return it->second;
}

} // namespace
Expand All @@ -78,7 +74,7 @@ bool MatchesPattern(const base::string16& input,
UErrorCode status = U_ZERO_ERROR;
UBool match = matcher->find(0, status);
DCHECK(U_SUCCESS(status));
return !!match;
return match == TRUE;
}

} // namespace autofill

0 comments on commit cbca971

Please sign in to comment.