Skip to content

Commit

Permalink
Bug 1297981 - Delete BufferList::FlattenBytes and Pickle::FlattenByte…
Browse files Browse the repository at this point in the history
…s. r=billm

MozReview-Commit-ID: G3a4DN4Lovi
  • Loading branch information
kanru committed Aug 25, 2016
1 parent ee78688 commit 23050c8
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 120 deletions.
25 changes: 0 additions & 25 deletions ipc/chromium/src/base/pickle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -396,31 +396,6 @@ bool Pickle::ReadWString(PickleIterator* iter, std::wstring* result) const {
return true;
}

bool Pickle::FlattenBytes(PickleIterator* iter, const char** data, uint32_t length,
uint32_t alignment) {
DCHECK(iter);
DCHECK(data);
DCHECK(alignment == 4 || alignment == 8);
DCHECK(intptr_t(header_) % alignment == 0);

if (AlignInt(length) < length) {
return false;
}

uint32_t padding_len = intptr_t(iter->iter_.Data()) % alignment;
if (!iter->iter_.AdvanceAcrossSegments(buffers_, padding_len)) {
return false;
}

if (!buffers_.FlattenBytes(iter->iter_, data, length)) {
return false;
}

header_ = reinterpret_cast<Header*>(buffers_.Start());

return iter->iter_.AdvanceAcrossSegments(buffers_, AlignInt(length) - length);
}

bool Pickle::ExtractBuffers(PickleIterator* iter, size_t length, BufferList* buffers,
uint32_t alignment) const
{
Expand Down
2 changes: 0 additions & 2 deletions ipc/chromium/src/base/pickle.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ class Pickle {
MOZ_MUST_USE bool ReadString(PickleIterator* iter, std::string* result) const;
MOZ_MUST_USE bool ReadWString(PickleIterator* iter, std::wstring* result) const;
MOZ_MUST_USE bool ReadBytesInto(PickleIterator* iter, void* data, uint32_t length) const;
MOZ_MUST_USE bool FlattenBytes(PickleIterator* iter, const char** data, uint32_t length,
uint32_t alignment = sizeof(memberAlignmentType));
MOZ_MUST_USE bool ExtractBuffers(PickleIterator* iter, size_t length, BufferList* buffers,
uint32_t alignment = sizeof(memberAlignmentType)) const;

Expand Down
70 changes: 0 additions & 70 deletions mfbt/BufferList.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ class BufferList : private AllocPolicy
// to be full (i.e., size == capacity). Therefore, a byte at offset N within
// the BufferList and stored in memory at an address A will satisfy
// (N % Align == A % Align) if Align == 2, 4, or 8.
//
// NB: FlattenBytes can create non-full segments in the middle of the
// list. However, it ensures that these buffers are 8-byte aligned, so the
// offset invariant is not violated.
static const size_t kSegmentAlignment = 8;

// Allocate a BufferList. The BufferList will free all its buffers when it is
Expand Down Expand Up @@ -244,14 +240,6 @@ class BufferList : private AllocPolicy
// data before aSize.
inline bool ReadBytes(IterImpl& aIter, char* aData, size_t aSize) const;

// FlattenBytes reconfigures the BufferList so that data in the range
// [aIter, aIter + aSize) is stored contiguously. A pointer to this data is
// returned in aOutData. Returns false if not enough data is available. All
// other iterators are invalidated by this method.
//
// This method requires aIter and aSize to be 8-byte aligned.
inline bool FlattenBytes(IterImpl& aIter, const char** aOutData, size_t aSize);

// Return a new BufferList that shares storage with this BufferList. The new
// BufferList is read-only. It allows iteration over aSize bytes starting at
// aIter. Borrow can fail, in which case *aSuccess will be false upon
Expand Down Expand Up @@ -372,64 +360,6 @@ BufferList<AllocPolicy>::ReadBytes(IterImpl& aIter, char* aData, size_t aSize) c
return true;
}

template<typename AllocPolicy>
bool
BufferList<AllocPolicy>::FlattenBytes(IterImpl& aIter, const char** aOutData, size_t aSize)
{
MOZ_RELEASE_ASSERT(aSize);
MOZ_RELEASE_ASSERT(mOwning);

if (aIter.HasRoomFor(aSize)) {
// If the data is already contiguous, just return a pointer.
*aOutData = aIter.Data();
aIter.Advance(*this, aSize);
return true;
}

// This buffer will become the new contiguous segment.
char* buffer = this->template pod_malloc<char>(Size());
if (!buffer) {
return false;
}

size_t copied = 0;
size_t offset;
bool found = false;
for (size_t i = 0; i < mSegments.length(); i++) {
Segment& segment = mSegments[i];
memcpy(buffer + copied, segment.Start(), segment.mSize);

if (i == aIter.mSegment) {
offset = copied + (aIter.mData - segment.Start());

// Do we have aSize bytes after aIter?
if (Size() - offset >= aSize) {
found = true;
*aOutData = buffer + offset;

aIter.mSegment = 0;
aIter.mData = buffer + offset + aSize;
aIter.mDataEnd = buffer + Size();
}
}

this->free_(segment.mData);

copied += segment.mSize;
}

mSegments.clear();
mSegments.infallibleAppend(Segment(buffer, Size(), Size()));

if (!found) {
aIter.mSegment = 0;
aIter.mData = Start();
aIter.mDataEnd = Start() + Size();
}

return found;
}

template<typename AllocPolicy> template<typename BorrowingAllocPolicy>
BufferList<BorrowingAllocPolicy>
BufferList<AllocPolicy>::Borrow(IterImpl& aIter, size_t aSize, bool* aSuccess,
Expand Down
23 changes: 0 additions & 23 deletions mfbt/tests/TestBufferList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,29 +167,6 @@ int main(void)
MOZ_RELEASE_ASSERT(iter.RemainingInSegment() == kLastSegmentSize);
MOZ_RELEASE_ASSERT(unsigned(*iter.Data()) == (kTotalSize - kLastSegmentSize - kInitialSize - kSmallWrite) % 37);

// Flattening.

const size_t kFlattenSize = 1000;

const char* flat;
iter = bl.Iter();
MOZ_RELEASE_ASSERT(iter.AdvanceAcrossSegments(bl, kInitialSize));
MOZ_RELEASE_ASSERT(bl.FlattenBytes(iter, &flat, kFlattenSize));
MOZ_RELEASE_ASSERT(flat[0] == 0x0a);
MOZ_RELEASE_ASSERT(flat[kSmallWrite / 2] == 0x0a);
for (size_t i = kSmallWrite; i < kFlattenSize; i++) {
MOZ_RELEASE_ASSERT(unsigned(flat[i]) == (i - kSmallWrite) % 37);
}
MOZ_RELEASE_ASSERT(unsigned(*iter.Data()) == (kFlattenSize - kSmallWrite) % 37);

const size_t kSecondFlattenSize = 40;

MOZ_RELEASE_ASSERT(bl.FlattenBytes(iter, &flat, kSecondFlattenSize));
for (size_t i = 0; i < kSecondFlattenSize; i++) {
MOZ_RELEASE_ASSERT(unsigned(flat[i]) == (i + kFlattenSize - kInitialSize) % 37);
}
MOZ_RELEASE_ASSERT(iter.Done());

// Clear.

bl.Clear();
Expand Down

0 comments on commit 23050c8

Please sign in to comment.