OLD | NEW |
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 Loading... |
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 Loading... |
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_ |
OLD | NEW |