mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +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
Notes:
sideshowbarker
2024-07-17 08:59:18 +09:00
Author: https://github.com/LucasChollet Commit: https://github.com/SerenityOS/serenity/commit/398f7ae988 Pull-request: https://github.com/SerenityOS/serenity/pull/19915 Reviewed-by: https://github.com/timschumi ✅ Reviewed-by: https://github.com/trflynn89
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
Reference in a new issue