Skip to content

Commit 398f7ae

Browse files
LucasChollettrflynn89
authored andcommitted
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%.
1 parent 44bedf7 commit 398f7ae

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

AK/MemoryStream.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,14 @@ ErrorOr<Bytes> AllocatingMemoryStream::next_write_range()
270270

271271
void AllocatingMemoryStream::cleanup_unused_chunks()
272272
{
273-
// FIXME: Move these all at once.
274-
while (m_read_offset >= CHUNK_SIZE) {
275-
VERIFY(m_write_offset >= m_read_offset);
273+
VERIFY(m_write_offset >= m_read_offset);
276274

277-
auto buffer = m_chunks.take_first();
278-
m_read_offset -= CHUNK_SIZE;
279-
m_write_offset -= CHUNK_SIZE;
280-
}
275+
auto const chunks_to_remove = m_read_offset / CHUNK_SIZE;
276+
277+
m_chunks.remove(0, chunks_to_remove);
278+
279+
m_read_offset -= CHUNK_SIZE * chunks_to_remove;
280+
m_write_offset -= CHUNK_SIZE * chunks_to_remove;
281281
}
282282

283283
}

0 commit comments

Comments
 (0)