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

Side by Side Diff: url/scheme_host_port.cc

Issue 2560033002: [url] Reserve space for "scheme://host/" for SchemeHostPort serialization (Closed)
Patch Set: Created 4 years 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "url/scheme_host_port.h" 5 #include "url/scheme_host_port.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <tuple> 10 #include <tuple>
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 bool SchemeHostPort::operator<(const SchemeHostPort& other) const { 195 bool SchemeHostPort::operator<(const SchemeHostPort& other) const {
196 return std::tie(port_, scheme_, host_) < 196 return std::tie(port_, scheme_, host_) <
197 std::tie(other.port_, other.scheme_, other.host_); 197 std::tie(other.port_, other.scheme_, other.host_);
198 } 198 }
199 199
200 std::string SchemeHostPort::SerializeInternal(url::Parsed* parsed) const { 200 std::string SchemeHostPort::SerializeInternal(url::Parsed* parsed) const {
201 std::string result; 201 std::string result;
202 if (IsInvalid()) 202 if (IsInvalid())
203 return result; 203 return result;
204 204
205 // Reserve enough space for the "normal" case of scheme://host/.
206 result.reserve(scheme_.size() + host_.size() + 4);
207
205 if (!scheme_.empty()) { 208 if (!scheme_.empty()) {
206 parsed->scheme = Component(0, scheme_.length()); 209 parsed->scheme = Component(0, scheme_.length());
207 result.append(scheme_); 210 result.append(scheme_);
208 } 211 }
209 212
210 result.append(kStandardSchemeSeparator); 213 result.append(kStandardSchemeSeparator);
211 214
212 if (!host_.empty()) { 215 if (!host_.empty()) {
213 parsed->host = Component(result.length(), host_.length()); 216 parsed->host = Component(result.length(), host_.length());
214 result.append(host_); 217 result.append(host_);
(...skipping 12 matching lines...) Expand all
227 result.push_back(':'); 230 result.push_back(':');
228 std::string port(base::UintToString(port_)); 231 std::string port(base::UintToString(port_));
229 parsed->port = Component(result.length(), port.length()); 232 parsed->port = Component(result.length(), port.length());
230 result.append(std::move(port)); 233 result.append(std::move(port));
231 } 234 }
232 235
233 return result; 236 return result;
234 } 237 }
235 238
236 } // namespace url 239 } // namespace url
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698