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

Unified Diff: components/safe_browsing_db/util.cc

Issue 1494613002: Reduce number of string allocations in util.cc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mattm@ comments. Created 5 years 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/safe_browsing_db/util.cc
diff --git a/components/safe_browsing_db/util.cc b/components/safe_browsing_db/util.cc
index 9507075a79daf0a6857d2c26b4ffdac16a53ee8d..0636a14513b0bc8f436c2cb486d9b011512f71c5 100644
--- a/components/safe_browsing_db/util.cc
+++ b/components/safe_browsing_db/util.cc
@@ -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;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698