mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:04:59 +00:00
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:
parent
44bedf7844
commit
398f7ae988
1 changed files with 7 additions and 7 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue