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

Side by Side Diff: base/pickle.cc

Issue 39463002: Introduce Pickle::{Read,Write}PODArray to serialize arrays of POD (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 return (payload_end > end) ? NULL : payload_end; 298 return (payload_end > end) ? NULL : payload_end;
299 } 299 }
300 300
301 template <size_t length> void Pickle::WriteBytesStatic(const void* data) { 301 template <size_t length> void Pickle::WriteBytesStatic(const void* data) {
302 WriteBytesCommon(data, length); 302 WriteBytesCommon(data, length);
303 } 303 }
304 304
305 template void Pickle::WriteBytesStatic<2>(const void* data); 305 template void Pickle::WriteBytesStatic<2>(const void* data);
306 template void Pickle::WriteBytesStatic<4>(const void* data); 306 template void Pickle::WriteBytesStatic<4>(const void* data);
307 template void Pickle::WriteBytesStatic<8>(const void* data); 307 template void Pickle::WriteBytesStatic<8>(const void* data);
308 template void Pickle::WriteBytesStatic<16>(const void* data);
309 template void Pickle::WriteBytesStatic<64>(const void* data);
308 310
309 inline void Pickle::WriteBytesCommon(const void* data, size_t length) { 311 inline void Pickle::WriteBytesCommon(const void* data, size_t length) {
310 DCHECK_NE(kCapacityReadOnly, capacity_after_header_) 312 DCHECK_NE(kCapacityReadOnly, capacity_after_header_)
311 << "oops: pickle is readonly"; 313 << "oops: pickle is readonly";
312 size_t data_len = AlignInt(length, sizeof(uint32)); 314 size_t data_len = AlignInt(length, sizeof(uint32));
313 DCHECK_GE(data_len, length); 315 DCHECK_GE(data_len, length);
314 #ifdef ARCH_CPU_64_BITS 316 #ifdef ARCH_CPU_64_BITS
315 DCHECK_LE(data_len, kuint32max); 317 DCHECK_LE(data_len, kuint32max);
316 #endif 318 #endif
317 DCHECK_LE(write_offset_, kuint32max - data_len); 319 DCHECK_LE(write_offset_, kuint32max - data_len);
318 size_t new_size = write_offset_ + data_len; 320 size_t new_size = write_offset_ + data_len;
319 if (new_size > capacity_after_header_) { 321 if (new_size > capacity_after_header_) {
320 Resize(std::max(capacity_after_header_ * 2, new_size)); 322 Resize(std::max(capacity_after_header_ * 2, new_size));
321 } 323 }
322 324
323 char* write = mutable_payload() + write_offset_; 325 char* write = mutable_payload() + write_offset_;
324 memcpy(write, data, length); 326 memcpy(write, data, length);
325 memset(write + length, 0, data_len - length); 327 memset(write + length, 0, data_len - length);
326 header_->payload_size = static_cast<uint32>(write_offset_ + length); 328 header_->payload_size = static_cast<uint32>(write_offset_ + length);
327 write_offset_ = new_size; 329 write_offset_ = new_size;
328 } 330 }
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