From 3f7d97f0984f9e24013c5545608437c949811920 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 27 Jul 2023 15:05:13 +0100 Subject: [PATCH] AK+Libraries: Remove `FixedMemoryStream::[readonly_]bytes()` These methods are slightly more convenient than storing the Bytes separately. However, it it feels unsanitary to reach in and access this data directly. Both of the users of these already have the [Readonly]Bytes available in their constructors, and can easily avoid using these methods, so let's remove them entirely. --- AK/MemoryStream.cpp | 10 ---------- AK/MemoryStream.h | 2 -- Userland/Libraries/LibGfx/ImageFormats/TGALoader.cpp | 10 ++++++---- Userland/Libraries/LibVideo/VP9/Context.h | 9 ++++++--- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/AK/MemoryStream.cpp b/AK/MemoryStream.cpp index 0a04962580..ad4967f370 100644 --- a/AK/MemoryStream.cpp +++ b/AK/MemoryStream.cpp @@ -109,16 +109,6 @@ ErrorOr FixedMemoryStream::write_until_depleted(ReadonlyBytes bytes) return {}; } -Bytes FixedMemoryStream::bytes() -{ - VERIFY(m_writing_enabled); - return m_bytes; -} -ReadonlyBytes FixedMemoryStream::readonly_bytes() const -{ - return m_bytes; -} - size_t FixedMemoryStream::offset() const { return m_offset; diff --git a/AK/MemoryStream.h b/AK/MemoryStream.h index 84d5a5a58a..4f514169ff 100644 --- a/AK/MemoryStream.h +++ b/AK/MemoryStream.h @@ -31,8 +31,6 @@ public: virtual ErrorOr write_some(ReadonlyBytes bytes) override; virtual ErrorOr write_until_depleted(ReadonlyBytes bytes) override; - Bytes bytes(); - ReadonlyBytes readonly_bytes() const; size_t offset() const; size_t remaining() const; diff --git a/Userland/Libraries/LibGfx/ImageFormats/TGALoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/TGALoader.cpp index 686a99311c..088d570d10 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/TGALoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/TGALoader.cpp @@ -51,10 +51,12 @@ struct AK::Traits : public GenericTraits { namespace Gfx { struct TGALoadingContext { - TGALoadingContext(FixedMemoryStream stream) - : stream(move(stream)) + TGALoadingContext(ReadonlyBytes bytes, FixedMemoryStream stream) + : bytes(bytes) + , stream(move(stream)) { } + ReadonlyBytes bytes; FixedMemoryStream stream; TGAHeader header {}; RefPtr bitmap; @@ -85,7 +87,7 @@ static ErrorOr ensure_header_validity(TGAHeader const& header, size_t whol ErrorOr TGAImageDecoderPlugin::decode_tga_header() { m_context->header = TRY(m_context->stream.read_value()); - TRY(ensure_header_validity(m_context->header, m_context->stream.readonly_bytes().size())); + TRY(ensure_header_validity(m_context->header, m_context->bytes.size())); return {}; } @@ -99,7 +101,7 @@ ErrorOr TGAImageDecoderPlugin::validate_before_create(ReadonlyBytes data) ErrorOr> TGAImageDecoderPlugin::create(ReadonlyBytes data) { FixedMemoryStream stream { data }; - auto context = TRY(adopt_nonnull_own_or_enomem(new (nothrow) TGALoadingContext(move(stream)))); + auto context = TRY(adopt_nonnull_own_or_enomem(new (nothrow) TGALoadingContext(data, move(stream)))); auto plugin = TRY(adopt_nonnull_own_or_enomem(new (nothrow) TGAImageDecoderPlugin(move(context)))); TRY(plugin->decode_tga_header()); return plugin; diff --git a/Userland/Libraries/LibVideo/VP9/Context.h b/Userland/Libraries/LibVideo/VP9/Context.h index 58bcf5bae5..051099534f 100644 --- a/Userland/Libraries/LibVideo/VP9/Context.h +++ b/Userland/Libraries/LibVideo/VP9/Context.h @@ -46,6 +46,7 @@ public: Vector2D& contexts) { return FrameContext( + data, TRY(try_make(data)), TRY(try_make()), contexts); @@ -54,12 +55,12 @@ public: FrameContext(FrameContext const&) = delete; FrameContext(FrameContext&&) = default; + ReadonlyBytes stream_data; NonnullOwnPtr stream; BigEndianInputBitStream bit_stream; DecoderErrorOr create_range_decoder(size_t size) { - ReadonlyBytes stream_data = stream->readonly_bytes(); auto compressed_header_data = ReadonlyBytes(stream_data.data() + stream->offset(), size); // 9.2.1: The Boolean decoding process specified in section 9.2.2 is invoked to read a marker syntax element from the @@ -178,10 +179,12 @@ public: private: friend struct TileContext; - FrameContext(NonnullOwnPtr stream, + FrameContext(ReadonlyBytes data, + NonnullOwnPtr stream, NonnullOwnPtr counter, Vector2D& contexts) - : stream(move(stream)) + : stream_data(data) + , stream(move(stream)) , bit_stream(MaybeOwned(*this->stream)) , counter(move(counter)) , m_block_contexts(contexts)