Bug 1581049 - BlocksRingBuffer (de)serializer uses optimized inter-ModuloBuffer copier - r=gregtatum

Instead of copying `BlocksRingBuffer` data byte-by-byte (using iterators byte
dereferencers), we can now use `ModuloBuffer::Iterator::ReadInto(Iterator&)` to
copy them using a small number of `memcpy`s.

Differential Revision: https://phabricator.services.mozilla.com/D45839

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Gerald Squelart 2019-09-18 01:22:42 +00:00
Родитель 229768ce0a
Коммит 64ec6b96a0
1 изменённых файлов: 5 добавлений и 13 удалений

Просмотреть файл

@ -2003,13 +2003,8 @@ struct BlocksRingBuffer::Serializer<BlocksRingBuffer> {
aEW.WriteULEB128<Length>(len);
aEW.WriteObject(start);
aEW.WriteObject(end);
// Write all the bytes. TODO: Optimize with memcpy's?
const auto readerEnd =
aBuffer.mMaybeUnderlyingBuffer->mBuffer.ReaderAt(end);
for (auto reader = aBuffer.mMaybeUnderlyingBuffer->mBuffer.ReaderAt(start);
reader != readerEnd; ++reader) {
aEW.WriteObject(*reader);
}
// Write all the bytes.
aBuffer.mMaybeUnderlyingBuffer->mBuffer.ReaderAt(start).ReadInto(aEW, len);
// And write stats.
aEW.WriteObject(aBuffer.mMaybeUnderlyingBuffer->mPushedBlockCount);
aEW.WriteObject(aBuffer.mMaybeUnderlyingBuffer->mClearedBlockCount);
@ -2046,12 +2041,9 @@ struct BlocksRingBuffer::Deserializer<BlocksRingBuffer> {
aBuffer.mNextWriteIndex = BlocksRingBuffer::BlockIndex(end);
MOZ_ASSERT(end - start == len);
// Copy bytes into the buffer.
const auto writerEnd =
aBuffer.mMaybeUnderlyingBuffer->mBuffer.WriterAt(end);
for (auto writer = aBuffer.mMaybeUnderlyingBuffer->mBuffer.WriterAt(start);
writer != writerEnd; ++writer, ++aER) {
*writer = *aER;
}
auto writer = aBuffer.mMaybeUnderlyingBuffer->mBuffer.WriterAt(start);
aER.ReadInto(writer, len);
MOZ_ASSERT(writer.CurrentIndex() == end);
// Finally copy stats.
aBuffer.mMaybeUnderlyingBuffer->mPushedBlockCount = aER.ReadObject<decltype(
aBuffer.mMaybeUnderlyingBuffer->mPushedBlockCount)>();