mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-03 14:50:18 +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: 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()
|
void AllocatingMemoryStream::cleanup_unused_chunks()
|
||||||
{
|
{
|
||||||
// FIXME: Move these all at once.
|
VERIFY(m_write_offset >= m_read_offset);
|
||||||
while (m_read_offset >= CHUNK_SIZE) {
|
|
||||||
VERIFY(m_write_offset >= m_read_offset);
|
|
||||||
|
|
||||||
auto buffer = m_chunks.take_first();
|
auto const chunks_to_remove = m_read_offset / CHUNK_SIZE;
|
||||||
m_read_offset -= CHUNK_SIZE;
|
|
||||||
m_write_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