mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-25 20:22:18 +03:00
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.
This commit is contained in:
parent
109ea418ab
commit
3f7d97f098
Notes:
sideshowbarker
2024-07-17 06:00:02 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/3f7d97f098 Pull-request: https://github.com/SerenityOS/serenity/pull/20223
@ -109,16 +109,6 @@ ErrorOr<void> 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;
|
||||
|
@ -31,8 +31,6 @@ public:
|
||||
virtual ErrorOr<size_t> write_some(ReadonlyBytes bytes) override;
|
||||
virtual ErrorOr<void> write_until_depleted(ReadonlyBytes bytes) override;
|
||||
|
||||
Bytes bytes();
|
||||
ReadonlyBytes readonly_bytes() const;
|
||||
size_t offset() const;
|
||||
size_t remaining() const;
|
||||
|
||||
|
@ -51,10 +51,12 @@ struct AK::Traits<Gfx::TGAHeader> : public GenericTraits<Gfx::TGAHeader> {
|
||||
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<Gfx::Bitmap> bitmap;
|
||||
@ -85,7 +87,7 @@ static ErrorOr<void> ensure_header_validity(TGAHeader const& header, size_t whol
|
||||
ErrorOr<void> TGAImageDecoderPlugin::decode_tga_header()
|
||||
{
|
||||
m_context->header = TRY(m_context->stream.read_value<TGAHeader>());
|
||||
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<bool> TGAImageDecoderPlugin::validate_before_create(ReadonlyBytes data)
|
||||
ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> 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;
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
Vector2D<FrameBlockContext>& contexts)
|
||||
{
|
||||
return FrameContext(
|
||||
data,
|
||||
TRY(try_make<FixedMemoryStream>(data)),
|
||||
TRY(try_make<SyntaxElementCounter>()),
|
||||
contexts);
|
||||
@ -54,12 +55,12 @@ public:
|
||||
FrameContext(FrameContext const&) = delete;
|
||||
FrameContext(FrameContext&&) = default;
|
||||
|
||||
ReadonlyBytes stream_data;
|
||||
NonnullOwnPtr<FixedMemoryStream> stream;
|
||||
BigEndianInputBitStream bit_stream;
|
||||
|
||||
DecoderErrorOr<BooleanDecoder> 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<FixedMemoryStream> stream,
|
||||
FrameContext(ReadonlyBytes data,
|
||||
NonnullOwnPtr<FixedMemoryStream> stream,
|
||||
NonnullOwnPtr<SyntaxElementCounter> counter,
|
||||
Vector2D<FrameBlockContext>& contexts)
|
||||
: stream(move(stream))
|
||||
: stream_data(data)
|
||||
, stream(move(stream))
|
||||
, bit_stream(MaybeOwned<Stream>(*this->stream))
|
||||
, counter(move(counter))
|
||||
, m_block_contexts(contexts)
|
||||
|
Loading…
Reference in New Issue
Block a user