Commit e65382a5 authored by Christoph Schwering's avatar Christoph Schwering Committed by Chromium LUCI CQ

[Autofill] Use string pieces instead of strings for regexes.

This CL migrates the input and pattern base::string16 of
autofill::MatchPattern() to base::StringPiece16.

Bug: 1007974
Change-Id: I6c5c1b21ad39bc6317bbc51e1e5c3c4b24455aee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2628289
Commit-Queue: Matthias Körber <koerber@google.com>
Auto-Submit: Christoph Schwering <schwering@google.com>
Reviewed-by: default avatarMatthias Körber <koerber@google.com>
Cr-Commit-Position: refs/heads/master@{#844044}
parent d76f77d4
......@@ -4,8 +4,8 @@
#include "components/autofill/core/browser/autofill_regexes.h"
#include <map>
#include <memory>
#include <unordered_map>
#include <utility>
#include "base/check.h"
......@@ -28,19 +28,20 @@ class AutofillRegexes {
AutofillRegexes() = default;
// Returns the compiled regex matcher corresponding to |pattern|.
icu::RegexMatcher* GetMatcher(const base::string16& pattern);
icu::RegexMatcher* GetMatcher(const base::StringPiece16& pattern);
private:
~AutofillRegexes() = default;
// Maps patterns to their corresponding regex matchers.
std::unordered_map<base::string16, std::unique_ptr<icu::RegexMatcher>>
std::map<base::string16, std::unique_ptr<icu::RegexMatcher>, std::less<>>
matchers_;
DISALLOW_COPY_AND_ASSIGN(AutofillRegexes);
};
icu::RegexMatcher* AutofillRegexes::GetMatcher(const base::string16& pattern) {
icu::RegexMatcher* AutofillRegexes::GetMatcher(
const base::StringPiece16& pattern) {
auto it = matchers_.find(pattern);
if (it == matchers_.end()) {
const icu::UnicodeString icu_pattern(false, pattern.data(),
......@@ -62,8 +63,8 @@ icu::RegexMatcher* AutofillRegexes::GetMatcher(const base::string16& pattern) {
namespace autofill {
bool MatchesPattern(const base::string16& input,
const base::string16& pattern,
bool MatchesPattern(const base::StringPiece16& input,
const base::StringPiece16& pattern,
base::string16* match,
int32_t group_to_be_captured) {
static base::NoDestructor<AutofillRegexes> g_autofill_regexes;
......
......@@ -6,6 +6,7 @@
#define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_REGEXES_H_
#include "base/strings/string16.h"
#include "base/strings/string_piece.h"
// Parsing utilities.
namespace autofill {
......@@ -13,8 +14,8 @@ namespace autofill {
// Case-insensitive regular expression matching.
// Returns true if |pattern| is found in |input|.
// The |group_to_be_captured| numbered group is captured into |match|.
bool MatchesPattern(const base::string16& input,
const base::string16& pattern,
bool MatchesPattern(const base::StringPiece16& input,
const base::StringPiece16& pattern,
base::string16* match = nullptr,
int32_t group_to_be_captured = 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment