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

Side by Side Diff: url/url_canon_stdstring.cc

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_stdstring.h ('k') | url/url_util.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 #include "url/url_canon_stdstring.h" 5 #include "url/url_canon_stdstring.h"
6 6
7 namespace url { 7 namespace url {
8 8
9 StdStringCanonOutput::StdStringCanonOutput(std::string* str) 9 StdStringCanonOutput::StdStringCanonOutput(std::string* str)
10 : CanonOutput(), str_(str) { 10 : CanonOutput(), str_(str) {
11 cur_len_ = static_cast<int>(str_->size()); // Append to existing data. 11 cur_len_ = static_cast<int>(str_->size()); // Append to existing data.
12 str_->resize(str_->capacity());
13 buffer_ = str_->empty() ? NULL : &(*str_)[0]; 12 buffer_ = str_->empty() ? NULL : &(*str_)[0];
14 buffer_len_ = static_cast<int>(str_->size()); 13 buffer_len_ = static_cast<int>(str_->size());
15 } 14 }
16 15
17 StdStringCanonOutput::~StdStringCanonOutput() { 16 StdStringCanonOutput::~StdStringCanonOutput() {
18 // Nothing to do, we don't own the string. 17 // Nothing to do, we don't own the string.
19 } 18 }
20 19
21 void StdStringCanonOutput::Complete() { 20 void StdStringCanonOutput::Complete() {
22 str_->resize(cur_len_); 21 str_->resize(cur_len_);
23 buffer_len_ = cur_len_; 22 buffer_len_ = cur_len_;
24 } 23 }
25 24
26 void StdStringCanonOutput::Resize(int sz) { 25 void StdStringCanonOutput::Resize(int sz) {
27 str_->resize(sz); 26 str_->resize(sz);
28 buffer_ = str_->empty() ? NULL : &(*str_)[0]; 27 buffer_ = str_->empty() ? NULL : &(*str_)[0];
29 buffer_len_ = sz; 28 buffer_len_ = sz;
30 } 29 }
31 30
32 } // namespace url 31 } // namespace url
OLDNEW
« no previous file with comments | « url/url_canon_stdstring.h ('k') | url/url_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698