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

Unified Diff: url/url_util.cc

Issue 2617173003: [url] Reserve output buffer for various URL parsing paths (Closed)
Patch Set: brettw review Created 3 years, 11 months 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 | « url/url_canon_relative.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: url/url_util.cc
diff --git a/url/url_util.cc b/url/url_util.cc
index b3e360424152668e0a786883ad206734fc657366..f98f4b877f432804d7580e268fe7c900824b3c13 100644
--- a/url/url_util.cc
+++ b/url/url_util.cc
@@ -169,6 +169,10 @@ bool DoCanonicalize(const CHAR* spec,
CharsetConverter* charset_converter,
CanonOutput* output,
Parsed* output_parsed) {
+ // Reserve enough room in the output for the input, plus some extra so that
+ // we have room if we have to escape a few things without reallocating.
+ output->ReserveSizeIfNeeded(spec_len + 8);
+
// Remove any whitespace from the middle of the relative URL if necessary.
// Possibly this will result in copying to the new buffer.
RawCanonOutputT<CHAR> whitespace_buffer;
@@ -278,6 +282,9 @@ bool DoResolveRelative(const char* base_spec,
return false;
}
+ // Don't reserve buffer space here. Instead, reserve in DoCanonicalize and
+ // ReserveRelativeURL, to enable more accurate buffer sizes.
+
// Pretend for a moment that |base_spec| is a standard URL. Normally
// non-standard URLs are treated as PathURLs, but if the base has an
// authority we would like to preserve it.
@@ -380,6 +387,12 @@ bool DoReplaceComponents(const char* spec,
charset_converter, output, out_parsed);
}
+ // TODO(csharrison): We could be smarter about size to reserve if this is done
+ // in callers below, and the code checks to see which components are being
+ // replaced, and with what length. If this ends up being a hot spot it should
+ // be changed.
+ output->ReserveSizeIfNeeded(spec_len + 8);
+
// If we get here, then we know the scheme doesn't need to be replaced, so can
// just key off the scheme in the spec to know how to do the replacements.
if (DoCompareSchemeComponent(spec, parsed.scheme, url::kFileScheme)) {
« no previous file with comments | « url/url_canon_relative.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698