mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 09:34:57 +09: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: 3f7d97f098
Pull-request: https://github.com/SerenityOS/serenity/pull/20223
4 changed files with 12 additions and 19 deletions
|
@ -109,16 +109,6 @@ ErrorOr<void> FixedMemoryStream::write_until_depleted(ReadonlyBytes bytes)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Bytes FixedMemoryStream::bytes()
|
|
||||||
{
|
|
||||||
VERIFY(m_writing_enabled);
|
|
||||||
return m_bytes;
|
|
||||||
}
|
|
||||||
ReadonlyBytes FixedMemoryStream::readonly_bytes() const
|
|
||||||
{
|
|
||||||
return m_bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t FixedMemoryStream::offset() const
|
size_t FixedMemoryStream::offset() const
|
||||||
{
|
{
|
||||||
return m_offset;
|
return m_offset;
|
||||||
|
|
|
@ -31,8 +31,6 @@ public:
|
||||||
virtual ErrorOr<size_t> write_some(ReadonlyBytes bytes) override;
|
virtual ErrorOr<size_t> write_some(ReadonlyBytes bytes) override;
|
||||||
virtual ErrorOr<void> write_until_depleted(ReadonlyBytes bytes) override;
|
virtual ErrorOr<void> write_until_depleted(ReadonlyBytes bytes) override;
|
||||||
|
|
||||||
Bytes bytes();
|
|
||||||
ReadonlyBytes readonly_bytes() const;
|
|
||||||
size_t offset() const;
|
size_t offset() const;
|
||||||
size_t remaining() const;
|
size_t remaining() const;
|
||||||
|
|
||||||
|
|
|
@ -51,10 +51,12 @@ struct AK::Traits<Gfx::TGAHeader> : public GenericTraits<Gfx::TGAHeader> {
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
|
||||||
struct TGALoadingContext {
|
struct TGALoadingContext {
|
||||||
TGALoadingContext(FixedMemoryStream stream)
|
TGALoadingContext(ReadonlyBytes bytes, FixedMemoryStream stream)
|
||||||
: stream(move(stream))
|
: bytes(bytes)
|
||||||
|
, stream(move(stream))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
ReadonlyBytes bytes;
|
||||||
FixedMemoryStream stream;
|
FixedMemoryStream stream;
|
||||||
TGAHeader header {};
|
TGAHeader header {};
|
||||||
RefPtr<Gfx::Bitmap> bitmap;
|
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()
|
ErrorOr<void> TGAImageDecoderPlugin::decode_tga_header()
|
||||||
{
|
{
|
||||||
m_context->header = TRY(m_context->stream.read_value<TGAHeader>());
|
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 {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +101,7 @@ ErrorOr<bool> TGAImageDecoderPlugin::validate_before_create(ReadonlyBytes data)
|
||||||
ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> TGAImageDecoderPlugin::create(ReadonlyBytes data)
|
ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> TGAImageDecoderPlugin::create(ReadonlyBytes data)
|
||||||
{
|
{
|
||||||
FixedMemoryStream stream { 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))));
|
auto plugin = TRY(adopt_nonnull_own_or_enomem(new (nothrow) TGAImageDecoderPlugin(move(context))));
|
||||||
TRY(plugin->decode_tga_header());
|
TRY(plugin->decode_tga_header());
|
||||||
return plugin;
|
return plugin;
|
||||||
|
|
|
@ -46,6 +46,7 @@ public:
|
||||||
Vector2D<FrameBlockContext>& contexts)
|
Vector2D<FrameBlockContext>& contexts)
|
||||||
{
|
{
|
||||||
return FrameContext(
|
return FrameContext(
|
||||||
|
data,
|
||||||
TRY(try_make<FixedMemoryStream>(data)),
|
TRY(try_make<FixedMemoryStream>(data)),
|
||||||
TRY(try_make<SyntaxElementCounter>()),
|
TRY(try_make<SyntaxElementCounter>()),
|
||||||
contexts);
|
contexts);
|
||||||
|
@ -54,12 +55,12 @@ public:
|
||||||
FrameContext(FrameContext const&) = delete;
|
FrameContext(FrameContext const&) = delete;
|
||||||
FrameContext(FrameContext&&) = default;
|
FrameContext(FrameContext&&) = default;
|
||||||
|
|
||||||
|
ReadonlyBytes stream_data;
|
||||||
NonnullOwnPtr<FixedMemoryStream> stream;
|
NonnullOwnPtr<FixedMemoryStream> stream;
|
||||||
BigEndianInputBitStream bit_stream;
|
BigEndianInputBitStream bit_stream;
|
||||||
|
|
||||||
DecoderErrorOr<BooleanDecoder> create_range_decoder(size_t size)
|
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);
|
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
|
// 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:
|
private:
|
||||||
friend struct TileContext;
|
friend struct TileContext;
|
||||||
|
|
||||||
FrameContext(NonnullOwnPtr<FixedMemoryStream> stream,
|
FrameContext(ReadonlyBytes data,
|
||||||
|
NonnullOwnPtr<FixedMemoryStream> stream,
|
||||||
NonnullOwnPtr<SyntaxElementCounter> counter,
|
NonnullOwnPtr<SyntaxElementCounter> counter,
|
||||||
Vector2D<FrameBlockContext>& contexts)
|
Vector2D<FrameBlockContext>& contexts)
|
||||||
: stream(move(stream))
|
: stream_data(data)
|
||||||
|
, stream(move(stream))
|
||||||
, bit_stream(MaybeOwned<Stream>(*this->stream))
|
, bit_stream(MaybeOwned<Stream>(*this->stream))
|
||||||
, counter(move(counter))
|
, counter(move(counter))
|
||||||
, m_block_contexts(contexts)
|
, m_block_contexts(contexts)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue