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

Side by Side Diff: url/url_canon_relative.cc

Issue 2641823004: [url] Reserve size in a smarter way to account for pre-allocated buffers (Closed)
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « url/url_canon.h ('k') | url/url_canon_stdstring.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Canonicalizer functions for working with and resolving relative URLs. 5 // Canonicalizer functions for working with and resolving relative URLs.
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "url/url_canon.h" 10 #include "url/url_canon.h"
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 // We know the authority section didn't change, copy it to the output. We 281 // We know the authority section didn't change, copy it to the output. We
282 // also know we have a path so can copy up to there. 282 // also know we have a path so can copy up to there.
283 Component path, query, ref; 283 Component path, query, ref;
284 ParsePathInternal(relative_url, relative_component, &path, &query, &ref); 284 ParsePathInternal(relative_url, relative_component, &path, &query, &ref);
285 285
286 // Canonical URLs always have a path, so we can use that offset. Reserve 286 // Canonical URLs always have a path, so we can use that offset. Reserve
287 // enough room for the base URL, the new path, and some extra bytes for 287 // enough room for the base URL, the new path, and some extra bytes for
288 // possible escaped characters. 288 // possible escaped characters.
289 output->ReserveSizeIfNeeded( 289 output->ReserveSizeIfNeeded(
290 base_parsed.path.begin + 290 base_parsed.path.begin +
291 std::max(path.end(), std::max(query.end(), ref.end())) + 8); 291 std::max(path.end(), std::max(query.end(), ref.end())));
292 output->Append(base_url, base_parsed.path.begin); 292 output->Append(base_url, base_parsed.path.begin);
293 293
294 if (path.len > 0) { 294 if (path.len > 0) {
295 // The path is replaced or modified. 295 // The path is replaced or modified.
296 int true_path_begin = output->length(); 296 int true_path_begin = output->length();
297 297
298 // For file: URLs on Windows, we don't want to treat the drive letter and 298 // For file: URLs on Windows, we don't want to treat the drive letter and
299 // colon as part of the path for relative file resolution when the 299 // colon as part of the path for relative file resolution when the
300 // incoming URL does not provide a drive spec. We save the true path 300 // incoming URL does not provide a drive spec. We save the true path
301 // beginning so we can fix it up after we are done. 301 // beginning so we can fix it up after we are done.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 replacements.SetHost(relative_url, relative_parsed.host); 399 replacements.SetHost(relative_url, relative_parsed.host);
400 replacements.SetPort(relative_url, relative_parsed.port); 400 replacements.SetPort(relative_url, relative_parsed.port);
401 replacements.SetPath(relative_url, relative_parsed.path); 401 replacements.SetPath(relative_url, relative_parsed.path);
402 replacements.SetQuery(relative_url, relative_parsed.query); 402 replacements.SetQuery(relative_url, relative_parsed.query);
403 replacements.SetRef(relative_url, relative_parsed.ref); 403 replacements.SetRef(relative_url, relative_parsed.ref);
404 404
405 // Length() does not include the old scheme, so make sure to add it from the 405 // Length() does not include the old scheme, so make sure to add it from the
406 // base URL. 406 // base URL.
407 output->ReserveSizeIfNeeded( 407 output->ReserveSizeIfNeeded(
408 replacements.components().Length() + 408 replacements.components().Length() +
409 base_parsed.CountCharactersBefore(Parsed::USERNAME, false) + 8); 409 base_parsed.CountCharactersBefore(Parsed::USERNAME, false));
410 return ReplaceStandardURL(base_url, base_parsed, replacements, 410 return ReplaceStandardURL(base_url, base_parsed, replacements,
411 query_converter, output, out_parsed); 411 query_converter, output, out_parsed);
412 } 412 }
413 413
414 // Resolves a relative URL that happens to be an absolute file path. Examples 414 // Resolves a relative URL that happens to be an absolute file path. Examples
415 // include: "//hostname/path", "/c:/foo", and "//hostname/c:/foo". 415 // include: "//hostname/path", "/c:/foo", and "//hostname/c:/foo".
416 template<typename CHAR> 416 template<typename CHAR>
417 bool DoResolveAbsoluteFile(const CHAR* relative_url, 417 bool DoResolveAbsoluteFile(const CHAR* relative_url,
418 const Component& relative_component, 418 const Component& relative_component,
419 CharsetConverter* query_converter, 419 CharsetConverter* query_converter,
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 const Component& relative_component, 568 const Component& relative_component,
569 CharsetConverter* query_converter, 569 CharsetConverter* query_converter,
570 CanonOutput* output, 570 CanonOutput* output,
571 Parsed* out_parsed) { 571 Parsed* out_parsed) {
572 return DoResolveRelativeURL<base::char16>( 572 return DoResolveRelativeURL<base::char16>(
573 base_url, base_parsed, base_is_file, relative_url, 573 base_url, base_parsed, base_is_file, relative_url,
574 relative_component, query_converter, output, out_parsed); 574 relative_component, query_converter, output, out_parsed);
575 } 575 }
576 576
577 } // namespace url 577 } // namespace url
OLDNEW
« no previous file with comments | « url/url_canon.h ('k') | url/url_canon_stdstring.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698