mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 16:45:03 +00: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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user