mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:34:59 +00:00
AK: Expose AllocatingMemoryStream::CHUNK_SIZE
This allows the tests to use that information confidently.
This commit is contained in:
parent
2b8a527478
commit
9a7ae52b31
3 changed files with 18 additions and 18 deletions
|
@ -199,8 +199,8 @@ ErrorOr<Optional<size_t>> AllocatingMemoryStream::offset_of(ReadonlyBytes needle
|
|||
return Optional<size_t> {};
|
||||
|
||||
// Ensure that we don't have to trim away more than one block.
|
||||
VERIFY(m_read_offset < chunk_size);
|
||||
VERIFY(m_chunks.size() * chunk_size - m_write_offset < chunk_size);
|
||||
VERIFY(m_read_offset < CHUNK_SIZE);
|
||||
VERIFY(m_chunks.size() * CHUNK_SIZE - m_write_offset < CHUNK_SIZE);
|
||||
|
||||
auto chunk_count = m_chunks.size();
|
||||
auto search_spans = TRY(FixedArray<ReadonlyBytes>::create(chunk_count));
|
||||
|
@ -210,7 +210,7 @@ ErrorOr<Optional<size_t>> AllocatingMemoryStream::offset_of(ReadonlyBytes needle
|
|||
}
|
||||
|
||||
// Trimming is done first to ensure that we don't unintentionally shift around if the first and last chunks are the same.
|
||||
search_spans[chunk_count - 1] = search_spans[chunk_count - 1].trim(m_write_offset % chunk_size);
|
||||
search_spans[chunk_count - 1] = search_spans[chunk_count - 1].trim(m_write_offset % CHUNK_SIZE);
|
||||
search_spans[0] = search_spans[0].slice(m_read_offset);
|
||||
|
||||
return AK::memmem(search_spans.begin(), search_spans.end(), needle);
|
||||
|
@ -220,9 +220,9 @@ ErrorOr<ReadonlyBytes> AllocatingMemoryStream::next_read_range()
|
|||
{
|
||||
VERIFY(m_write_offset >= m_read_offset);
|
||||
|
||||
size_t const chunk_index = m_read_offset / chunk_size;
|
||||
size_t const chunk_offset = m_read_offset % chunk_size;
|
||||
size_t const read_size = min(chunk_size - m_read_offset % chunk_size, m_write_offset - m_read_offset);
|
||||
size_t const chunk_index = m_read_offset / CHUNK_SIZE;
|
||||
size_t const chunk_offset = m_read_offset % CHUNK_SIZE;
|
||||
size_t const read_size = min(CHUNK_SIZE - m_read_offset % CHUNK_SIZE, m_write_offset - m_read_offset);
|
||||
|
||||
if (read_size == 0)
|
||||
return ReadonlyBytes { static_cast<u8*>(nullptr), 0 };
|
||||
|
@ -236,12 +236,12 @@ ErrorOr<Bytes> AllocatingMemoryStream::next_write_range()
|
|||
{
|
||||
VERIFY(m_write_offset >= m_read_offset);
|
||||
|
||||
size_t const chunk_index = m_write_offset / chunk_size;
|
||||
size_t const chunk_offset = m_write_offset % chunk_size;
|
||||
size_t const write_size = chunk_size - m_write_offset % chunk_size;
|
||||
size_t const chunk_index = m_write_offset / CHUNK_SIZE;
|
||||
size_t const chunk_offset = m_write_offset % CHUNK_SIZE;
|
||||
size_t const write_size = CHUNK_SIZE - m_write_offset % CHUNK_SIZE;
|
||||
|
||||
if (chunk_index >= m_chunks.size())
|
||||
TRY(m_chunks.try_append(TRY(Chunk::create_uninitialized(chunk_size))));
|
||||
TRY(m_chunks.try_append(TRY(Chunk::create_uninitialized(CHUNK_SIZE))));
|
||||
|
||||
VERIFY(chunk_index < m_chunks.size());
|
||||
|
||||
|
@ -251,12 +251,12 @@ ErrorOr<Bytes> AllocatingMemoryStream::next_write_range()
|
|||
void AllocatingMemoryStream::cleanup_unused_chunks()
|
||||
{
|
||||
// FIXME: Move these all at once.
|
||||
while (m_read_offset >= chunk_size) {
|
||||
while (m_read_offset >= CHUNK_SIZE) {
|
||||
VERIFY(m_write_offset >= m_read_offset);
|
||||
|
||||
auto buffer = m_chunks.take_first();
|
||||
m_read_offset -= chunk_size;
|
||||
m_write_offset -= chunk_size;
|
||||
m_read_offset -= CHUNK_SIZE;
|
||||
m_write_offset -= CHUNK_SIZE;
|
||||
|
||||
m_chunks.append(move(buffer));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue