summaryrefslogtreecommitdiffstats
path: root/base/pickle_unittest.cc
diff options
context:
space:
mode:
authorerikchen <erikchen@chromium.org>2015-09-08 16:36:29 -0700
committererikchen <erikchen@chromium.org>2015-09-08 23:38:42 +0000
commitf9ca8f5f0656036f8062be85a38b0f243bb0df34 (patch)
tree8a4cc4fd492a5522f5e20f39d9df9d3c991b80eb /base/pickle_unittest.cc
parent207ddf4c6885c8165363b4f75485665530ab1fbb (diff)
downloadchromium_src-f9ca8f5f0656036f8062be85a38b0f243bb0df34.zip
chromium_src-f9ca8f5f0656036f8062be85a38b0f243bb0df34.tar.gz
chromium_src-f9ca8f5f0656036f8062be85a38b0f243bb0df34.tar.bz2
base: Fix an inefficiency in base::Pickle that caused extraneous allocations.
The Resize() method is supposed to be passed the size of the payload, not including the header. In the copy constructor, it was being passed the size of the payload plus the header. BUG= R=mark@chromium.org Review URL: https://codereview.chromium.org/1327523006 . Cr-Commit-Position: refs/heads/master@{#347826}
Diffstat (limited to 'base/pickle_unittest.cc')
-rw-r--r--base/pickle_unittest.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/base/pickle_unittest.cc b/base/pickle_unittest.cc
index b0a8f21..6f9fcc7 100644
--- a/base/pickle_unittest.cc
+++ b/base/pickle_unittest.cc
@@ -428,4 +428,18 @@ TEST(PickleTest, ReadBytes) {
EXPECT_EQ(data, outdata);
}
+// Checks that when a pickle is deep-copied, the result is not larger than
+// needed.
+TEST(PickleTest, DeepCopyResize) {
+ Pickle pickle;
+ while (pickle.capacity_after_header() != pickle.payload_size())
+ pickle.WriteBool(true);
+
+ // Make a deep copy.
+ Pickle pickle2(pickle);
+
+ // Check that there isn't any extraneous capacity.
+ EXPECT_EQ(pickle.capacity_after_header(), pickle2.capacity_after_header());
+}
+
} // namespace base