Commit 93e29f7d authored by mpearson's avatar mpearson Committed by Commit bot

TemplateURL Performance - don't call replace search terms

That's a heavy function to call.  I removed the call.

The only thing it was being used for apparently was to get the port.
Frankly, I don't see much importance in checking the port of
search engines, but I added port_ and a cached internal variable
to maintain this support and entirely removed the heavy call.

For reference, the port line was part of a large change
https://chromium.googlesource.com/chromium/src/+/5b30787532fe44ff67e29fbbedfb1781663a4f06%5E%21/#F8
for which there was no motivating discussion about the need to check
ports.  I guess there's no harm in it though.

BUG=

Review URL: https://codereview.chromium.org/1595103007

Cr-Commit-Position: refs/heads/master@{#371851}
parent e92b7c2b
......@@ -457,14 +457,9 @@ bool TemplateURLRef::ExtractSearchTermsFromURL(
(search_term_key_location_ != url::Parsed::PATH))
return false;
// Fill-in the replacements. We don't care about search terms in the pattern,
// so we use the empty string.
// Currently we assume the search term only shows in URL, not in post params.
GURL pattern(ReplaceSearchTerms(SearchTermsArgs(base::string16()),
search_terms_data, NULL));
// Host, path and port must match.
if ((url.port() != pattern.port()) ||
(url.host() != host_) ||
// Host, port, and path must match.
if ((url.host() != host_) ||
(url.port() != port_) ||
((url.path() != path_) &&
(search_term_key_location_ != url::Parsed::PATH))) {
return false;
......@@ -521,6 +516,7 @@ bool TemplateURLRef::ExtractSearchTermsFromURL(
void TemplateURLRef::InvalidateCachedValues() const {
supports_replacements_ = valid_ = parsed_ = false;
host_.clear();
port_.clear();
path_.clear();
search_term_key_.clear();
search_term_position_in_path_ = std::string::npos;
......@@ -771,12 +767,6 @@ void TemplateURLRef::ParseHostAndSearchTermKey(
&url_string, 0, "{google:baseSuggestURL}",
search_terms_data.GoogleBaseSuggestURLValue());
search_term_key_.clear();
search_term_position_in_path_ = std::string::npos;
host_.clear();
path_.clear();
search_term_key_location_ = url::Parsed::QUERY;
GURL url(url_string);
if (!url.is_valid())
return;
......@@ -791,6 +781,7 @@ void TemplateURLRef::ParseHostAndSearchTermKey(
return; // No key or multiple keys found. We only handle having one key.
host_ = url.host();
port_ = url.port();
path_ = url.path();
if (in_query) {
search_term_key_ = query_key;
......
......@@ -453,9 +453,10 @@ class TemplateURLRef {
// into the string, and may be empty.
mutable Replacements replacements_;
// Host, path, key and location of the search term. These are only set if the
// url contains one search term.
// Host, port, path, key and location of the search term. These are only set
// if the url contains one search term.
mutable std::string host_;
mutable std::string port_;
mutable std::string path_;
mutable std::string search_term_key_;
mutable size_t search_term_position_in_path_;
......
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