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

Side by Side Diff: url/url_canon_stdstring.h

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_relative.cc ('k') | url/url_canon_stdstring.cc » ('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 #ifndef URL_URL_CANON_STDSTRING_H_ 5 #ifndef URL_URL_CANON_STDSTRING_H_
6 #define URL_URL_CANON_STDSTRING_H_ 6 #define URL_URL_CANON_STDSTRING_H_
7 7
8 // This header file defines a canonicalizer output method class for STL 8 // This header file defines a canonicalizer output method class for STL
9 // strings. Because the canonicalizer tries not to be dependent on the STL, 9 // strings. Because the canonicalizer tries not to be dependent on the STL,
10 // we have segregated it here. 10 // we have segregated it here.
11 11
12 #include <string> 12 #include <string>
13 13
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/strings/string_piece.h" 15 #include "base/strings/string_piece.h"
16 #include "url/url_canon.h" 16 #include "url/url_canon.h"
17 #include "url/url_export.h" 17 #include "url/url_export.h"
18 18
19 namespace url { 19 namespace url {
20 20
21 // Write into a std::string given in the constructor. This object does not own 21 // Write into a std::string given in the constructor. This object does not own
22 // the string itself, and the user must ensure that the string stays alive 22 // the string itself, and the user must ensure that the string stays alive
23 // throughout the lifetime of this object. 23 // throughout the lifetime of this object.
24 // 24 //
25 // The given string will be appended to; any existing data in the string will 25 // The given string will be appended to; any existing data in the string will
26 // be preserved. The caller should reserve() the amount of data in the string 26 // be preserved.
27 // they expect to be written. We will resize if necessary, but that's slow.
28 // 27 //
29 // Note that when canonicalization is complete, the string will likely have 28 // Note that when canonicalization is complete, the string will likely have
30 // unused space at the end because we make the string very big to start out 29 // unused space at the end because we make the string very big to start out
31 // with (by |initial_size|). This ends up being important because resize 30 // with (by |initial_size|). This ends up being important because resize
32 // operations are slow, and because the base class needs to write directly 31 // operations are slow, and because the base class needs to write directly
33 // into the buffer. 32 // into the buffer.
34 // 33 //
35 // Therefore, the user should call Complete() before using the string that 34 // Therefore, the user should call Complete() before using the string that
36 // this class wrote into. 35 // this class wrote into.
37 class URL_EXPORT StdStringCanonOutput : public CanonOutput { 36 class URL_EXPORT StdStringCanonOutput : public CanonOutput {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 this->SetQuery(s.data(), Component(0, static_cast<int>(s.length()))); 77 this->SetQuery(s.data(), Component(0, static_cast<int>(s.length())));
79 } 78 }
80 void SetRefStr(const base::BasicStringPiece<STR>& s) { 79 void SetRefStr(const base::BasicStringPiece<STR>& s) {
81 this->SetRef(s.data(), Component(0, static_cast<int>(s.length()))); 80 this->SetRef(s.data(), Component(0, static_cast<int>(s.length())));
82 } 81 }
83 }; 82 };
84 83
85 } // namespace url 84 } // namespace url
86 85
87 #endif // URL_URL_CANON_STDSTRING_H_ 86 #endif // URL_URL_CANON_STDSTRING_H_
OLDNEW
« no previous file with comments | « url/url_canon_relative.cc ('k') | url/url_canon_stdstring.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698