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

Side by Side Diff: base/pickle.cc

Issue 1327523006: base: Fix an inefficiency in base::Pickle that caused extraneous allocations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from mark. Created 5 years, 3 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 | « base/pickle.h ('k') | base/pickle_unittest.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/pickle.h" 5 #include "base/pickle.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <algorithm> // for max() 9 #include <algorithm> // for max()
10 10
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 // If there is anything wrong with the data, we're not going to use it. 247 // If there is anything wrong with the data, we're not going to use it.
248 if (!header_size_) 248 if (!header_size_)
249 header_ = NULL; 249 header_ = NULL;
250 } 250 }
251 251
252 Pickle::Pickle(const Pickle& other) 252 Pickle::Pickle(const Pickle& other)
253 : header_(NULL), 253 : header_(NULL),
254 header_size_(other.header_size_), 254 header_size_(other.header_size_),
255 capacity_after_header_(0), 255 capacity_after_header_(0),
256 write_offset_(other.write_offset_) { 256 write_offset_(other.write_offset_) {
257 size_t payload_size = header_size_ + other.header_->payload_size; 257 Resize(other.header_->payload_size);
258 Resize(payload_size); 258 memcpy(header_, other.header_, header_size_ + other.header_->payload_size);
259 memcpy(header_, other.header_, payload_size);
260 } 259 }
261 260
262 Pickle::~Pickle() { 261 Pickle::~Pickle() {
263 if (capacity_after_header_ != kCapacityReadOnly) 262 if (capacity_after_header_ != kCapacityReadOnly)
264 free(header_); 263 free(header_);
265 } 264 }
266 265
267 Pickle& Pickle::operator=(const Pickle& other) { 266 Pickle& Pickle::operator=(const Pickle& other) {
268 if (this == &other) { 267 if (this == &other) {
269 NOTREACHED(); 268 NOTREACHED();
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 } 379 }
381 380
382 char* write = mutable_payload() + write_offset_; 381 char* write = mutable_payload() + write_offset_;
383 memcpy(write, data, length); 382 memcpy(write, data, length);
384 memset(write + length, 0, data_len - length); 383 memset(write + length, 0, data_len - length);
385 header_->payload_size = static_cast<uint32>(new_size); 384 header_->payload_size = static_cast<uint32>(new_size);
386 write_offset_ = new_size; 385 write_offset_ = new_size;
387 } 386 }
388 387
389 } // namespace base 388 } // namespace base
OLDNEW
« no previous file with comments | « base/pickle.h ('k') | base/pickle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698