Commit 0e860e70 authored by Harsh Patel's avatar Harsh Patel Committed by Commit Bot

Address_rewriter_rules has strings instead of arrays

Encoded each table in address_rewriter_rules into single strings
separated by the null terminator. As a result address_rewriter parses
these strings instead.

This results in a decrease in binary size due to less read only
relocations.

Bug: 958792
Change-Id: I672c3541ddc52c9324bccf5f8ccae674c119518d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1682550
Commit-Queue: Sam Maier <smaier@chromium.org>
Reviewed-by: default avatarSam Maier <smaier@chromium.org>
Reviewed-by: default avatarRoger McFarlane <rogerm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#675814}
parent c398f1e8
......@@ -17,13 +17,12 @@ namespace {
// Import in the internal rule table symbols. The data is defined in
// components/autofill/core/browser/address_rewriter_rules.cc
using internal::Rule;
using internal::RegionInfo;
using internal::kRuleTable;
using internal::kRuleTableSize;
// Aliases for the types used by the compiled rules cache.
using CompiledRule = std::pair<std::unique_ptr<re2::RE2>, re2::StringPiece>;
using CompiledRule = std::pair<std::unique_ptr<re2::RE2>, const char *>;
using CompiledRuleVector = std::vector<CompiledRule>;
using CompiledRuleCache = std::unordered_map<std::string, CompiledRuleVector>;
......@@ -71,12 +70,15 @@ class Cache {
options.set_utf8(true);
options.set_word_boundary(true);
CompiledRuleVector& compiled_rules = data_[region];
compiled_rules.reserve(region_info->num_rules);
for (size_t i = 0; i < region_info->num_rules; ++i) {
const Rule& rule = region_info->rules[i];
std::unique_ptr<re2::RE2> pattern(new re2::RE2(rule.pattern, options));
re2::StringPiece rewrite(rule.rewrite);
compiled_rules.emplace_back(std::move(pattern), std::move(rewrite));
const char* iterator = region_info->rules;
for(size_t i = 0; i < region_info->num_rules; ++i){
auto pattern = std::make_unique<re2::RE2>(iterator, options);
iterator += strlen(iterator) + 1;
compiled_rules.emplace_back(std::move(pattern), iterator);
iterator += strlen(iterator) + 1;
}
// Return a pointer to the data.
......
......@@ -30,16 +30,10 @@ class AddressRewriter {
// Implementation details follow. Not part of the public interface.
namespace internal {
// The structure used to statically define a rule.
struct Rule {
const char* pattern;
const char* rewrite;
};
// The structure used to statically define a set of rules for a region.
struct RegionInfo {
const char* region;
const Rule* rules;
const char* rules;
size_t num_rules;
bool operator<(const base::StringPiece& region) const {
......
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