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

Side by Side Diff: base/pickle_unittest.cc

Issue 34413002: Pickle::Write* micro-optimizations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows 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.cc ('k') | 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 (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 <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/pickle.h" 9 #include "base/pickle.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 210
211 // construct a message that will be exactly the size of one payload unit, 211 // construct a message that will be exactly the size of one payload unit,
212 // note that any data will have a 4-byte header indicating the size 212 // note that any data will have a 4-byte header indicating the size
213 const size_t payload_size_after_header = unit - sizeof(uint32); 213 const size_t payload_size_after_header = unit - sizeof(uint32);
214 Pickle pickle; 214 Pickle pickle;
215 pickle.WriteData(data_ptr, 215 pickle.WriteData(data_ptr,
216 static_cast<int>(payload_size_after_header - sizeof(uint32))); 216 static_cast<int>(payload_size_after_header - sizeof(uint32)));
217 size_t cur_payload = payload_size_after_header; 217 size_t cur_payload = payload_size_after_header;
218 218
219 // note: we assume 'unit' is a power of 2 219 // note: we assume 'unit' is a power of 2
220 EXPECT_EQ(unit, pickle.capacity()); 220 EXPECT_EQ(unit, pickle.capacity_after_header());
221 EXPECT_EQ(pickle.payload_size(), payload_size_after_header); 221 EXPECT_EQ(pickle.payload_size(), payload_size_after_header);
222 222
223 // fill out a full page (noting data header) 223 // fill out a full page (noting data header)
224 pickle.WriteData(data_ptr, static_cast<int>(unit - sizeof(uint32))); 224 pickle.WriteData(data_ptr, static_cast<int>(unit - sizeof(uint32)));
225 cur_payload += unit; 225 cur_payload += unit;
226 EXPECT_EQ(unit * 2, pickle.capacity()); 226 EXPECT_EQ(unit * 2, pickle.capacity_after_header());
227 EXPECT_EQ(cur_payload, pickle.payload_size()); 227 EXPECT_EQ(cur_payload, pickle.payload_size());
228 228
229 // one more byte should double the capacity 229 // one more byte should double the capacity
230 pickle.WriteData(data_ptr, 1); 230 pickle.WriteData(data_ptr, 1);
231 cur_payload += 5; 231 cur_payload += 5;
232 EXPECT_EQ(unit * 4, pickle.capacity()); 232 EXPECT_EQ(unit * 4, pickle.capacity_after_header());
233 EXPECT_EQ(cur_payload, pickle.payload_size()); 233 EXPECT_EQ(cur_payload, pickle.payload_size());
234 } 234 }
235 235
236 namespace { 236 namespace {
237 237
238 struct CustomHeader : Pickle::Header { 238 struct CustomHeader : Pickle::Header {
239 int blah; 239 int blah;
240 }; 240 };
241 241
242 } // namespace 242 } // namespace
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 EXPECT_TRUE(pickle.WriteBytes(&data, sizeof(data))); 321 EXPECT_TRUE(pickle.WriteBytes(&data, sizeof(data)));
322 322
323 PickleIterator iter(pickle); 323 PickleIterator iter(pickle);
324 const char* outdata_char = NULL; 324 const char* outdata_char = NULL;
325 EXPECT_TRUE(pickle.ReadBytes(&iter, &outdata_char, sizeof(data))); 325 EXPECT_TRUE(pickle.ReadBytes(&iter, &outdata_char, sizeof(data)));
326 326
327 int outdata; 327 int outdata;
328 memcpy(&outdata, outdata_char, sizeof(outdata)); 328 memcpy(&outdata, outdata_char, sizeof(outdata));
329 EXPECT_EQ(data, outdata); 329 EXPECT_EQ(data, outdata);
330 } 330 }
OLDNEW
« no previous file with comments | « base/pickle.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698