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

Unified Diff: components/autofill/core/common/autofill_regexes.cc

Issue 1453193002: autofill: switch autofill_regexes to RE2 library (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: input is UTF8 Created 5 years, 1 month 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 | « components/autofill/core/common/DEPS ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/core/common/autofill_regexes.cc
diff --git a/components/autofill/core/common/autofill_regexes.cc b/components/autofill/core/common/autofill_regexes.cc
index cdea63cb5c83c1ab3bca8008a6fa2fe0c44b7a73..b570df7158a3e77239aef7013f3b10e02a37e901 100644
--- a/components/autofill/core/common/autofill_regexes.cc
+++ b/components/autofill/core/common/autofill_regexes.cc
@@ -9,7 +9,8 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "base/strings/string16.h"
-#include "third_party/icu/source/i18n/unicode/regex.h"
+#include "base/strings/utf_string_conversions.h"
+#include "third_party/re2/re2/re2.h"
namespace {
@@ -19,7 +20,7 @@ class AutofillRegexes {
static AutofillRegexes* GetInstance();
// Returns the compiled regex matcher corresponding to |pattern|.
- icu::RegexMatcher* GetMatcher(const base::string16& pattern);
+ re2::RE2* GetMatcher(const base::string16& pattern);
Evan Stade 2015/11/23 16:38:39 can you make this return a const ref?
private:
AutofillRegexes();
@@ -27,8 +28,7 @@ class AutofillRegexes {
friend struct base::DefaultSingletonTraits<AutofillRegexes>;
// Maps patterns to their corresponding regex matchers.
- base::ScopedPtrHashMap<base::string16, scoped_ptr<icu::RegexMatcher>>
- matchers_;
+ base::ScopedPtrHashMap<base::string16, scoped_ptr<re2::RE2>> matchers_;
DISALLOW_COPY_AND_ASSIGN(AutofillRegexes);
};
@@ -44,16 +44,14 @@ AutofillRegexes::AutofillRegexes() {
AutofillRegexes::~AutofillRegexes() {
}
-icu::RegexMatcher* AutofillRegexes::GetMatcher(const base::string16& pattern) {
+re2::RE2* AutofillRegexes::GetMatcher(const base::string16& pattern) {
Ilya Sherman 2015/11/20 22:27:59 Please either change this API to use std::string,
auto it = matchers_.find(pattern);
if (it == matchers_.end()) {
- const icu::UnicodeString icu_pattern(pattern.data(), pattern.length());
-
- UErrorCode status = U_ZERO_ERROR;
- scoped_ptr<icu::RegexMatcher> matcher(
- new icu::RegexMatcher(icu_pattern, UREGEX_CASE_INSENSITIVE, status));
- DCHECK(U_SUCCESS(status));
-
+ re2::RE2::Options options;
+ options.set_case_sensitive(false);
+ scoped_ptr<re2::RE2> matcher(
+ new re2::RE2(base::UTF16ToUTF8(pattern), options));
+ DCHECK(matcher->ok());
auto result = matchers_.add(pattern, matcher.Pass());
DCHECK(result.second);
it = result.first;
@@ -67,15 +65,11 @@ namespace autofill {
bool MatchesPattern(const base::string16& input,
const base::string16& pattern) {
Ilya Sherman 2015/11/20 22:27:59 Please either change this API to use std::string f
tfarina 2015/11/25 17:20:23 Done. But if I'm not wrong from looking at the log
- icu::RegexMatcher* matcher =
- AutofillRegexes::GetInstance()->GetMatcher(pattern);
- icu::UnicodeString icu_input(input.data(), input.length());
- matcher->reset(icu_input);
-
- UErrorCode status = U_ZERO_ERROR;
- UBool match = matcher->find(0, status);
- DCHECK(U_SUCCESS(status));
- return match == TRUE;
+ // TODO(isherman): Run performance tests to determine whether caching regex
+ // matchers is still useful now that we've switched from ICU to RE2.
+ // http://crbug.com/470065
+ re2::RE2* matcher = AutofillRegexes::GetInstance()->GetMatcher(pattern);
+ return re2::RE2::PartialMatch(base::UTF16ToUTF8(input), *matcher);
}
} // namespace autofill
« no previous file with comments | « components/autofill/core/common/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698