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

Side by Side Diff: url/url_canon.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 | « no previous file | url/url_canon_relative.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_H_ 5 #ifndef URL_URL_CANON_H_
6 #define URL_URL_CANON_H_ 6 #define URL_URL_CANON_H_
7 7
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 10
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 if (cur_len_ + str_len > buffer_len_) { 111 if (cur_len_ + str_len > buffer_len_) {
112 if (!Grow(cur_len_ + str_len - buffer_len_)) 112 if (!Grow(cur_len_ + str_len - buffer_len_))
113 return; 113 return;
114 } 114 }
115 for (int i = 0; i < str_len; i++) 115 for (int i = 0; i < str_len; i++)
116 buffer_[cur_len_ + i] = str[i]; 116 buffer_[cur_len_ + i] = str[i];
117 cur_len_ += str_len; 117 cur_len_ += str_len;
118 } 118 }
119 119
120 void ReserveSizeIfNeeded(int estimated_size) { 120 void ReserveSizeIfNeeded(int estimated_size) {
121 // Reserve a bit extra to account for escaped chars.
121 if (estimated_size > buffer_len_) 122 if (estimated_size > buffer_len_)
122 Resize(estimated_size); 123 Resize(estimated_size + 8);
123 } 124 }
124 125
125 protected: 126 protected:
126 // Grows the given buffer so that it can fit at least |min_additional| 127 // Grows the given buffer so that it can fit at least |min_additional|
127 // characters. Returns true if the buffer could be resized, false on OOM. 128 // characters. Returns true if the buffer could be resized, false on OOM.
128 bool Grow(int min_additional) { 129 bool Grow(int min_additional) {
129 static const int kMinBufferLen = 16; 130 static const int kMinBufferLen = 16;
130 int new_len = (buffer_len_ == 0) ? kMinBufferLen : buffer_len_; 131 int new_len = (buffer_len_ == 0) ? kMinBufferLen : buffer_len_;
131 do { 132 do {
132 if (new_len >= (1 << 30)) // Prevent overflow below. 133 if (new_len >= (1 << 30)) // Prevent overflow below.
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 bool base_is_file, 916 bool base_is_file,
916 const base::char16* relative_url, 917 const base::char16* relative_url,
917 const Component& relative_component, 918 const Component& relative_component,
918 CharsetConverter* query_converter, 919 CharsetConverter* query_converter,
919 CanonOutput* output, 920 CanonOutput* output,
920 Parsed* out_parsed); 921 Parsed* out_parsed);
921 922
922 } // namespace url 923 } // namespace url
923 924
924 #endif // URL_URL_CANON_H_ 925 #endif // URL_URL_CANON_H_
OLDNEW
« no previous file with comments | « no previous file | url/url_canon_relative.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698