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

Side by Side Diff: base/pickle.cc

Issue 35893002: IPC pickling optimization for render passes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ccmessagesperf-reserve: nits Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « base/pickle.h ('k') | content/common/cc_messages.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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 if (new_length < 0 || new_length > *cur_length) { 297 if (new_length < 0 || new_length > *cur_length) {
298 NOTREACHED() << "Invalid length in TrimWriteData."; 298 NOTREACHED() << "Invalid length in TrimWriteData.";
299 return; 299 return;
300 } 300 }
301 301
302 // Update the payload size and variable buffer size 302 // Update the payload size and variable buffer size
303 header_->payload_size -= (*cur_length - new_length); 303 header_->payload_size -= (*cur_length - new_length);
304 *cur_length = new_length; 304 *cur_length = new_length;
305 } 305 }
306 306
307 void Pickle::Reserve(size_t additional_capacity) {
308 // Write at a uint32-aligned offset from the beginning of the header.
309 size_t offset = AlignInt(header_->payload_size, sizeof(uint32));
310
311 size_t new_size = offset + additional_capacity;
312 size_t needed_size = header_size_ + new_size;
313 if (needed_size > capacity_)
314 Resize(capacity_ * 2 + needed_size);
315 }
316
307 char* Pickle::BeginWrite(size_t length) { 317 char* Pickle::BeginWrite(size_t length) {
308 // write at a uint32-aligned offset from the beginning of the header 318 // Write at a uint32-aligned offset from the beginning of the header.
309 size_t offset = AlignInt(header_->payload_size, sizeof(uint32)); 319 size_t offset = AlignInt(header_->payload_size, sizeof(uint32));
310 320
311 size_t new_size = offset + length; 321 size_t new_size = offset + length;
312 size_t needed_size = header_size_ + new_size; 322 size_t needed_size = header_size_ + new_size;
313 if (needed_size > capacity_ && !Resize(std::max(capacity_ * 2, needed_size))) 323 if (needed_size > capacity_ && !Resize(std::max(capacity_ * 2, needed_size)))
314 return NULL; 324 return NULL;
315 325
316 #ifdef ARCH_CPU_64_BITS 326 #ifdef ARCH_CPU_64_BITS
317 DCHECK_LE(length, kuint32max); 327 DCHECK_LE(length, kuint32max);
318 #endif 328 #endif
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 return NULL; 362 return NULL;
353 363
354 const Header* hdr = reinterpret_cast<const Header*>(start); 364 const Header* hdr = reinterpret_cast<const Header*>(start);
355 const char* payload_base = start + header_size; 365 const char* payload_base = start + header_size;
356 const char* payload_end = payload_base + hdr->payload_size; 366 const char* payload_end = payload_base + hdr->payload_size;
357 if (payload_end < payload_base) 367 if (payload_end < payload_base)
358 return NULL; 368 return NULL;
359 369
360 return (payload_end > end) ? NULL : payload_end; 370 return (payload_end > end) ? NULL : payload_end;
361 } 371 }
OLDNEW
« no previous file with comments | « base/pickle.h ('k') | content/common/cc_messages.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698