Commit 3f9f4d70 authored by georgesak's avatar georgesak Committed by Commit bot

Reduce number of string allocations in util.cc.

Replaces temporary string allocations with StringPiece.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#363054}
parent 45c8e9fd
......@@ -230,22 +230,21 @@ void CanonicalizeUrl(const GURL& url,
&parsed);
// 3. In hostname, remove all leading and trailing dots.
const std::string host =
(parsed.host.len > 0)
? url_unescaped_str.substr(parsed.host.begin, parsed.host.len)
: std::string();
std::string host_without_end_dots;
base::TrimString(host, ".", &host_without_end_dots);
base::StringPiece host;
if (parsed.host.len > 0)
host.set(url_unescaped_str.data() + parsed.host.begin, parsed.host.len);
base::StringPiece host_without_end_dots =
base::TrimString(host, ".", base::TrimPositions::TRIM_ALL);
// 4. In hostname, replace consecutive dots with a single dot.
std::string host_without_consecutive_dots(RemoveConsecutiveChars(
host_without_end_dots, '.'));
// 5. In path, replace runs of consecutive slashes with a single slash.
std::string path =
(parsed.path.len > 0)
? url_unescaped_str.substr(parsed.path.begin, parsed.path.len)
: std::string();
base::StringPiece path;
if (parsed.path.len > 0)
path.set(url_unescaped_str.data() + parsed.path.begin, parsed.path.len);
std::string path_without_consecutive_slash(RemoveConsecutiveChars(path, '/'));
url::Replacements<char> hp_replacements;
......
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