AK: Move chunks a single time in cleanup_unused_chunks()

All elements of the vector were moved to the left, for each element to
remove. This patch makes the function move each element exactly once.

On the same test case as the previous commit, it makes the function
disappear from the profile. These two commits combined reduce the
decompression time by 12%.
This commit is contained in:
Lucas CHOLLET 2023-07-10 20:34:56 -04:00 committed by Tim Flynn
parent 44bedf7844
commit 398f7ae988
Notes: sideshowbarker 2024-07-17 08:59:18 +09:00

View File

@ -270,14 +270,14 @@ ErrorOr<Bytes> AllocatingMemoryStream::next_write_range()
void AllocatingMemoryStream::cleanup_unused_chunks()
{
// FIXME: Move these all at once.
while (m_read_offset >= CHUNK_SIZE) {
VERIFY(m_write_offset >= m_read_offset);
VERIFY(m_write_offset >= m_read_offset);
auto buffer = m_chunks.take_first();
m_read_offset -= CHUNK_SIZE;
m_write_offset -= CHUNK_SIZE;
}
auto const chunks_to_remove = m_read_offset / CHUNK_SIZE;
m_chunks.remove(0, chunks_to_remove);
m_read_offset -= CHUNK_SIZE * chunks_to_remove;
m_write_offset -= CHUNK_SIZE * chunks_to_remove;
}
}