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 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 unified diff | Download patch
« no previous file with comments | « url/gurl.cc ('k') | 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 void Append(const T* str, int str_len) { 110 void Append(const T* str, int str_len) {
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) {
121 if (estimated_size > buffer_len_)
122 Resize(estimated_size);
123 }
124
120 protected: 125 protected:
121 // Grows the given buffer so that it can fit at least |min_additional| 126 // Grows the given buffer so that it can fit at least |min_additional|
122 // characters. Returns true if the buffer could be resized, false on OOM. 127 // characters. Returns true if the buffer could be resized, false on OOM.
123 bool Grow(int min_additional) { 128 bool Grow(int min_additional) {
124 static const int kMinBufferLen = 16; 129 static const int kMinBufferLen = 16;
125 int new_len = (buffer_len_ == 0) ? kMinBufferLen : buffer_len_; 130 int new_len = (buffer_len_ == 0) ? kMinBufferLen : buffer_len_;
126 do { 131 do {
127 if (new_len >= (1 << 30)) // Prevent overflow below. 132 if (new_len >= (1 << 30)) // Prevent overflow below.
128 return false; 133 return false;
129 new_len *= 2; 134 new_len *= 2;
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 bool base_is_file, 915 bool base_is_file,
911 const base::char16* relative_url, 916 const base::char16* relative_url,
912 const Component& relative_component, 917 const Component& relative_component,
913 CharsetConverter* query_converter, 918 CharsetConverter* query_converter,
914 CanonOutput* output, 919 CanonOutput* output,
915 Parsed* out_parsed); 920 Parsed* out_parsed);
916 921
917 } // namespace url 922 } // namespace url
918 923
919 #endif // URL_URL_CANON_H_ 924 #endif // URL_URL_CANON_H_
OLDNEW
« no previous file with comments | « url/gurl.cc ('k') | url/url_canon_relative.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698