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

Side by Side Diff: base/pickle_unittest.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.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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 421
422 PickleIterator iter(pickle); 422 PickleIterator iter(pickle);
423 const char* outdata_char = NULL; 423 const char* outdata_char = NULL;
424 EXPECT_TRUE(iter.ReadBytes(&outdata_char, sizeof(data))); 424 EXPECT_TRUE(iter.ReadBytes(&outdata_char, sizeof(data)));
425 425
426 int outdata; 426 int outdata;
427 memcpy(&outdata, outdata_char, sizeof(outdata)); 427 memcpy(&outdata, outdata_char, sizeof(outdata));
428 EXPECT_EQ(data, outdata); 428 EXPECT_EQ(data, outdata);
429 } 429 }
430 430
431 // Checks that when a pickle is deep-copied, the result is not larger than
432 // needed.
433 TEST(PickleTest, DeepCopyResize) {
434 Pickle pickle;
435 while (pickle.capacity_after_header() != pickle.payload_size())
436 pickle.WriteBool(true);
437
438 // Make a deep copy.
439 Pickle pickle2(pickle);
440
441 // Check that there isn't any extraneous capacity.
442 EXPECT_EQ(pickle.capacity_after_header(), pickle2.capacity_after_header());
443 }
444
431 } // namespace base 445 } // namespace base
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