Skip to content

Commit f9516a9

Browse files
asyntsawesomekling
authored andcommitted
AK: Remove history from DuplexMemoryStream.
That feature was really only useful for Compress::DeflateDecompressor but that is now using CircularDuplexBuffer instead.
1 parent 9ce4475 commit f9516a9

File tree

2 files changed

+5
-70
lines changed

2 files changed

+5
-70
lines changed

AK/Stream.h

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,9 @@ class InputMemoryStream final : public InputStream {
326326
// All data written to this stream can be read from it. Reading and writing is done
327327
// using different offsets, meaning that it is not necessary to seek to the start
328328
// before reading; this behaviour differs from BufferStream.
329-
//
330-
// The stream keeps a history of 64KiB which means that seeking backwards is well
331-
// defined. Data past that point will be discarded.
332329
class DuplexMemoryStream final : public DuplexStream {
333330
public:
334331
static constexpr size_t chunk_size = 4 * 1024;
335-
static constexpr size_t history_size = 64 * 1024;
336332

337333
bool eof() const override { return m_write_offset == m_read_offset; }
338334

@@ -411,22 +407,6 @@ class DuplexMemoryStream final : public DuplexStream {
411407
return nread;
412408
}
413409

414-
size_t read(Bytes bytes, size_t offset)
415-
{
416-
const auto backup = this->roffset();
417-
418-
bool do_discard_chunks = false;
419-
exchange(m_do_discard_chunks, do_discard_chunks);
420-
421-
rseek(offset);
422-
const auto count = read(bytes);
423-
rseek(backup);
424-
425-
exchange(m_do_discard_chunks, do_discard_chunks);
426-
427-
return count;
428-
}
429-
430410
bool read_or_error(Bytes bytes) override
431411
{
432412
if (m_write_offset - m_read_offset < bytes.size()) {
@@ -461,22 +441,12 @@ class DuplexMemoryStream final : public DuplexStream {
461441
size_t roffset() const { return m_read_offset; }
462442
size_t woffset() const { return m_write_offset; }
463443

464-
void rseek(size_t offset)
465-
{
466-
ASSERT(offset >= m_base_offset);
467-
ASSERT(offset <= m_write_offset);
468-
m_read_offset = offset;
469-
}
470-
471444
size_t remaining() const { return m_write_offset - m_read_offset; }
472445

473446
private:
474447
void try_discard_chunks()
475448
{
476-
if (!m_do_discard_chunks)
477-
return;
478-
479-
while (m_read_offset - m_base_offset >= history_size + chunk_size) {
449+
while (m_read_offset - m_base_offset >= chunk_size) {
480450
m_chunks.take_first();
481451
m_base_offset += chunk_size;
482452
}
@@ -486,7 +456,6 @@ class DuplexMemoryStream final : public DuplexStream {
486456
size_t m_write_offset { 0 };
487457
size_t m_read_offset { 0 };
488458
size_t m_base_offset { 0 };
489-
bool m_do_discard_chunks { false };
490459
};
491460

492461
}

AK/Tests/TestStream.cpp

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -123,61 +123,27 @@ TEST_CASE(duplex_simple)
123123
EXPECT(stream.eof());
124124
}
125125

126-
TEST_CASE(duplex_seek_into_history)
126+
TEST_CASE(duplex_large_buffer)
127127
{
128128
DuplexMemoryStream stream;
129129

130130
FixedArray<u8> one_kibibyte { 1024 };
131131

132132
EXPECT_EQ(stream.remaining(), 0ul);
133133

134-
for (size_t idx = 0; idx < 256; ++idx) {
134+
for (size_t idx = 0; idx < 256; ++idx)
135135
stream << one_kibibyte;
136-
}
137136

138137
EXPECT_EQ(stream.remaining(), 256 * 1024ul);
139138

140-
for (size_t idx = 0; idx < 128; ++idx) {
139+
for (size_t idx = 0; idx < 128; ++idx)
141140
stream >> one_kibibyte;
142-
}
143141

144142
EXPECT_EQ(stream.remaining(), 128 * 1024ul);
145143

146-
// We now have 128KiB on the stream. Because the stream has a
147-
// history size of 64KiB, we should be able to seek to 64KiB.
148-
static_assert(DuplexMemoryStream::history_size == 64 * 1024);
149-
stream.rseek(64 * 1024);
150-
151-
EXPECT_EQ(stream.remaining(), 192 * 1024ul);
152-
153-
for (size_t idx = 0; idx < 192; ++idx) {
144+
for (size_t idx = 0; idx < 128; ++idx)
154145
stream >> one_kibibyte;
155-
}
156-
157-
EXPECT(stream.eof());
158-
}
159-
160-
TEST_CASE(duplex_wild_seeking)
161-
{
162-
DuplexMemoryStream stream;
163-
164-
int input0 = 42, input1 = 13, input2 = -12;
165-
int output0, output1, output2;
166-
167-
stream << input2;
168-
stream << input0 << input1;
169-
stream.rseek(0);
170-
stream << input2 << input0;
171-
172-
stream.rseek(4);
173-
stream >> output0 >> output1 >> output2;
174-
175-
EXPECT(!stream.eof());
176-
EXPECT_EQ(input0, output0);
177-
EXPECT_EQ(input1, output1);
178-
EXPECT_EQ(input2, output2);
179146

180-
stream.discard_or_error(4);
181147
EXPECT(stream.eof());
182148
}
183149

0 commit comments

Comments
 (0)