diff options
author | piman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-30 20:32:07 +0000 |
---|---|---|
committer | piman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-30 20:32:07 +0000 |
commit | 7280f2f1c739cdfcd0337c6e040e05799c2b3693 (patch) | |
tree | d85a8df2cad4e31c297fc2ae5b58af401f09116f /base | |
parent | 54c1529f8d9906e174a4578a5dbdef30b23d21d8 (diff) | |
download | chromium_src-7280f2f1c739cdfcd0337c6e040e05799c2b3693.zip chromium_src-7280f2f1c739cdfcd0337c6e040e05799c2b3693.tar.gz chromium_src-7280f2f1c739cdfcd0337c6e040e05799c2b3693.tar.bz2 |
Remove Pickle::BeginWriteData/TrimWriteData, it's not used
BUG=None
R=jar@chromium.org
Review URL: https://codereview.chromium.org/38693003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231911 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/pickle.cc | 50 | ||||
-rw-r--r-- | base/pickle.h | 22 | ||||
-rw-r--r-- | base/pickle_unittest.cc | 12 |
3 files changed, 4 insertions, 80 deletions
diff --git a/base/pickle.cc b/base/pickle.cc index db78a4d..1d06af3 100644 --- a/base/pickle.cc +++ b/base/pickle.cc @@ -153,8 +153,7 @@ bool PickleIterator::ReadBytes(const char** data, int length) { Pickle::Pickle() : header_(NULL), header_size_(sizeof(Header)), - capacity_(0), - variable_buffer_offset_(0) { + capacity_(0) { Resize(kPayloadUnit); header_->payload_size = 0; } @@ -162,8 +161,7 @@ Pickle::Pickle() Pickle::Pickle(int header_size) : header_(NULL), header_size_(AlignInt(header_size, sizeof(uint32))), - capacity_(0), - variable_buffer_offset_(0) { + capacity_(0) { DCHECK_GE(static_cast<size_t>(header_size), sizeof(Header)); DCHECK_LE(header_size, kPayloadUnit); Resize(kPayloadUnit); @@ -173,8 +171,7 @@ Pickle::Pickle(int header_size) Pickle::Pickle(const char* data, size_t data_len) : header_(reinterpret_cast<Header*>(const_cast<char*>(data))), header_size_(0), - capacity_(kCapacityReadOnly), - variable_buffer_offset_(0) { + capacity_(kCapacityReadOnly) { if (data_len >= sizeof(Header)) header_size_ = data_len - header_->payload_size; @@ -192,8 +189,7 @@ Pickle::Pickle(const char* data, size_t data_len) Pickle::Pickle(const Pickle& other) : header_(NULL), header_size_(other.header_size_), - capacity_(0), - variable_buffer_offset_(other.variable_buffer_offset_) { + capacity_(0) { size_t payload_size = header_size_ + other.header_->payload_size; bool resized = Resize(payload_size); CHECK(resized); // Realloc failed. @@ -223,7 +219,6 @@ Pickle& Pickle::operator=(const Pickle& other) { CHECK(resized); // Realloc failed. memcpy(header_, other.header_, other.header_size_ + other.header_->payload_size); - variable_buffer_offset_ = other.variable_buffer_offset_; return *this; } @@ -267,43 +262,6 @@ bool Pickle::WriteBytes(const void* data, int data_len) { return true; } -char* Pickle::BeginWriteData(int length) { - DCHECK_EQ(variable_buffer_offset_, 0U) << - "There can only be one variable buffer in a Pickle"; - - if (length < 0 || !WriteInt(length)) - return NULL; - - char *data_ptr = BeginWrite(length); - if (!data_ptr) - return NULL; - - variable_buffer_offset_ = - data_ptr - reinterpret_cast<char*>(header_) - sizeof(int); - - // EndWrite doesn't necessarily have to be called after the write operation, - // so we call it here to pad out what the caller will eventually write. - EndWrite(data_ptr, length); - return data_ptr; -} - -void Pickle::TrimWriteData(int new_length) { - DCHECK_NE(variable_buffer_offset_, 0U); - - // Fetch the the variable buffer size - int* cur_length = reinterpret_cast<int*>( - reinterpret_cast<char*>(header_) + variable_buffer_offset_); - - if (new_length < 0 || new_length > *cur_length) { - NOTREACHED() << "Invalid length in TrimWriteData."; - return; - } - - // Update the payload size and variable buffer size - header_->payload_size -= (*cur_length - new_length); - *cur_length = new_length; -} - void Pickle::Reserve(size_t additional_capacity) { // Write at a uint32-aligned offset from the beginning of the header. size_t offset = AlignInt(header_->payload_size, sizeof(uint32)); diff --git a/base/pickle.h b/base/pickle.h index c90dbf4..41a6733 100644 --- a/base/pickle.h +++ b/base/pickle.h @@ -252,27 +252,6 @@ class BASE_EXPORT Pickle { // known size. See also WriteData. bool WriteBytes(const void* data, int data_len); - // Same as WriteData, but allows the caller to write directly into the - // Pickle. This saves a copy in cases where the data is not already - // available in a buffer. The caller should take care to not write more - // than the length it declares it will. Use ReadData to get the data. - // Returns NULL on failure. - // - // The returned pointer will only be valid until the next write operation - // on this Pickle. - char* BeginWriteData(int length); - - // For Pickles which contain variable length buffers (e.g. those created - // with BeginWriteData), the Pickle can - // be 'trimmed' if the amount of data required is less than originally - // requested. For example, you may have created a buffer with 10K of data, - // but decided to only fill 10 bytes of that data. Use this function - // to trim the buffer so that we don't send 9990 bytes of unused data. - // You cannot increase the size of the variable buffer; only shrink it. - // This function assumes that the length of the variable buffer has - // not been changed. - void TrimWriteData(int length); - // Reserves space for upcoming writes when multiple writes will be made and // their sizes are computed in advance. It can be significantly faster to call // Reserve() before calling WriteFoo() multiple times. @@ -358,7 +337,6 @@ class BASE_EXPORT Pickle { size_t header_size_; // Supports extra data between header and payload. // Allocation size of payload (or -1 if allocation is const). size_t capacity_; - size_t variable_buffer_offset_; // IF non-zero, then offset to a buffer. FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); diff --git a/base/pickle_unittest.cc b/base/pickle_unittest.cc index cc384c7..dd00e6a 100644 --- a/base/pickle_unittest.cc +++ b/base/pickle_unittest.cc @@ -58,10 +58,6 @@ void VerifyResult(const Pickle& pickle) { EXPECT_EQ(testdatalen, outdatalen); EXPECT_EQ(memcmp(testdata, outdata, outdatalen), 0); - EXPECT_TRUE(pickle.ReadData(&iter, &outdata, &outdatalen)); - EXPECT_EQ(testdatalen, outdatalen); - EXPECT_EQ(memcmp(testdata, outdata, outdatalen), 0); - // reads past the end should fail EXPECT_FALSE(pickle.ReadInt(&iter, &outint)); } @@ -79,14 +75,6 @@ TEST(PickleTest, EncodeDecode) { EXPECT_TRUE(pickle.WriteUInt16(testuint16)); EXPECT_TRUE(pickle.WriteFloat(testfloat)); EXPECT_TRUE(pickle.WriteData(testdata, testdatalen)); - - // Over allocate BeginWriteData so we can test TrimWriteData. - char* dest = pickle.BeginWriteData(testdatalen + 100); - EXPECT_TRUE(dest); - memcpy(dest, testdata, testdatalen); - - pickle.TrimWriteData(testdatalen); - VerifyResult(pickle); // test copy constructor |