Pickle::Write* micro-optimizations
Pickle is hot in some benchmarks. This helps by reworking WriteBytes in a few of ways:
1- Fold BeginWrite and EndWrite into WriteBytes since it's the only caller now.
2- keep track of the write offset, always aligned, separately, so that we can do alignment checks on the field sizes rather than the payload size (for next point).
3- provides a template version of WriteBytes with specializations for predefined sizes, that inline/optimize away alignment checks, padding, and memcpy.
4- change the meaning of capacity_ to not take the header size into account. This simplifies some arithmetic.
BUG=307480
[email protected]
Review URL: https://codereview.chromium.org/34413002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231987 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/base/pickle_unittest.cc b/base/pickle_unittest.cc
index dd00e6a..9dd0091 100644
--- a/base/pickle_unittest.cc
+++ b/base/pickle_unittest.cc
@@ -217,19 +217,19 @@
size_t cur_payload = payload_size_after_header;
// note: we assume 'unit' is a power of 2
- EXPECT_EQ(unit, pickle.capacity());
+ EXPECT_EQ(unit, pickle.capacity_after_header());
EXPECT_EQ(pickle.payload_size(), payload_size_after_header);
// fill out a full page (noting data header)
pickle.WriteData(data_ptr, static_cast<int>(unit - sizeof(uint32)));
cur_payload += unit;
- EXPECT_EQ(unit * 2, pickle.capacity());
+ EXPECT_EQ(unit * 2, pickle.capacity_after_header());
EXPECT_EQ(cur_payload, pickle.payload_size());
// one more byte should double the capacity
pickle.WriteData(data_ptr, 1);
cur_payload += 5;
- EXPECT_EQ(unit * 4, pickle.capacity());
+ EXPECT_EQ(unit * 4, pickle.capacity_after_header());
EXPECT_EQ(cur_payload, pickle.payload_size());
}