diff --git a/AK/Forward.h b/AK/Forward.h index dc73be66bd..c950a29063 100644 --- a/AK/Forward.h +++ b/AK/Forward.h @@ -53,7 +53,6 @@ class InputMemoryStream; class DuplexMemoryStream; class OutputStream; class InputBitStream; -class OutputMemoryStream; template class CircularDuplexStream; @@ -154,7 +153,6 @@ using AK::LogStream; using AK::NonnullOwnPtr; using AK::NonnullRefPtr; using AK::Optional; -using AK::OutputMemoryStream; using AK::OutputStream; using AK::OwnPtr; using AK::ReadonlyBytes; diff --git a/AK/MemoryStream.h b/AK/MemoryStream.h index 8a8bcd6196..0b1a2d311a 100644 --- a/AK/MemoryStream.h +++ b/AK/MemoryStream.h @@ -185,7 +185,7 @@ public: Optional offset_of(ReadonlyBytes value) const { - if (value.size() > remaining()) + if (value.size() > size()) return {}; // First, find which chunk we're in. @@ -288,7 +288,7 @@ public: ByteBuffer copy_into_contiguous_buffer() const { - auto buffer = ByteBuffer::create_uninitialized(remaining()); + auto buffer = ByteBuffer::create_uninitialized(size()); const auto nread = read_without_consuming(buffer); ASSERT(nread == buffer.size()); @@ -299,7 +299,7 @@ public: size_t roffset() const { return m_read_offset; } size_t woffset() const { return m_write_offset; } - size_t remaining() const { return m_write_offset - m_read_offset; } + size_t size() const { return m_write_offset - m_read_offset; } private: void try_discard_chunks() @@ -316,24 +316,8 @@ private: size_t m_base_offset { 0 }; }; -class OutputMemoryStream final : public OutputStream { -public: - size_t write(ReadonlyBytes bytes) override { return m_stream.write(bytes); } - bool write_or_error(ReadonlyBytes bytes) override { return m_stream.write_or_error(bytes); } - - ByteBuffer copy_into_contiguous_buffer() const { return m_stream.copy_into_contiguous_buffer(); } - - Optional offset_of(ReadonlyBytes value) const { return m_stream.offset_of(value); } - - size_t size() const { return m_stream.woffset(); } - -private: - DuplexMemoryStream m_stream; -}; - } using AK::DuplexMemoryStream; using AK::InputMemoryStream; using AK::InputStream; -using AK::OutputMemoryStream; diff --git a/AK/Tests/TestMemoryStream.cpp b/AK/Tests/TestMemoryStream.cpp index 9f17e0a27e..da419856be 100644 --- a/AK/Tests/TestMemoryStream.cpp +++ b/AK/Tests/TestMemoryStream.cpp @@ -129,17 +129,17 @@ TEST_CASE(duplex_large_buffer) Array one_kibibyte; - EXPECT_EQ(stream.remaining(), 0ul); + EXPECT_EQ(stream.size(), 0ul); for (size_t idx = 0; idx < 256; ++idx) stream << one_kibibyte; - EXPECT_EQ(stream.remaining(), 256 * 1024ul); + EXPECT_EQ(stream.size(), 256 * 1024ul); for (size_t idx = 0; idx < 128; ++idx) stream >> one_kibibyte; - EXPECT_EQ(stream.remaining(), 128 * 1024ul); + EXPECT_EQ(stream.size(), 128 * 1024ul); for (size_t idx = 0; idx < 128; ++idx) stream >> one_kibibyte; @@ -164,7 +164,7 @@ TEST_CASE(write_endian_values) { const u8 expected[] { 4, 3, 2, 1, 1, 2, 3, 4 }; - OutputMemoryStream stream; + DuplexMemoryStream stream; stream << LittleEndian { 0x01020304 } << BigEndian { 0x01020304 }; EXPECT_EQ(stream.size(), 8u); diff --git a/Libraries/LibCompress/Deflate.cpp b/Libraries/LibCompress/Deflate.cpp index dcd058b69c..59f2d5c2be 100644 --- a/Libraries/LibCompress/Deflate.cpp +++ b/Libraries/LibCompress/Deflate.cpp @@ -307,7 +307,7 @@ Optional DeflateDecompressor::decompress_all(ReadonlyBytes bytes) { InputMemoryStream memory_stream { bytes }; DeflateDecompressor deflate_stream { memory_stream }; - OutputMemoryStream output_stream; + DuplexMemoryStream output_stream; u8 buffer[4096]; while (!deflate_stream.has_any_error() && !deflate_stream.unreliable_eof()) { diff --git a/Libraries/LibCompress/Gzip.cpp b/Libraries/LibCompress/Gzip.cpp index de19a0ff3d..cbedc5843b 100644 --- a/Libraries/LibCompress/Gzip.cpp +++ b/Libraries/LibCompress/Gzip.cpp @@ -164,7 +164,7 @@ Optional GzipDecompressor::decompress_all(ReadonlyBytes bytes) { InputMemoryStream memory_stream { bytes }; GzipDecompressor gzip_stream { memory_stream }; - OutputMemoryStream output_stream; + DuplexMemoryStream output_stream; u8 buffer[4096]; while (!gzip_stream.has_any_error() && !gzip_stream.unreliable_eof()) { diff --git a/Shell/AST.cpp b/Shell/AST.cpp index 7c4882b3e4..366ff1b6c7 100644 --- a/Shell/AST.cpp +++ b/Shell/AST.cpp @@ -1107,7 +1107,7 @@ void Execute::for_each_entry(RefPtr shell, Function(String::copy(entry)));