From 7a55c4af0e6364387bd47b7739ad20c9c3cecf5a Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Wed, 8 May 2024 09:38:13 -0400 Subject: [PATCH] LibGfx/GIF: Avoid copying LZW subblocks twice I started to write that in order to remove the manual copy of the data but that should produce some performance gains as well. --- Userland/Libraries/LibGfx/ImageFormats/GIFLoader.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/GIFLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/GIFLoader.cpp index 81a2a74f550..d009be30819 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/GIFLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/GIFLoader.cpp @@ -33,7 +33,7 @@ struct GIFImageDescriptor { bool interlaced { false }; Color color_map[256]; u8 lzw_min_code_size { 0 }; - Vector lzw_encoded_bytes; + ByteBuffer lzw_encoded_bytes; // Fields from optional graphic control extension block enum DisposalMethod : u8 { @@ -357,12 +357,8 @@ static ErrorOr load_gif_frame_descriptors(GIFLoadingContext& context) if (lzw_encoded_bytes_expected == 0) break; - Array buffer; - TRY(context.stream.read_until_filled(buffer.span().trim(lzw_encoded_bytes_expected))); - - for (int i = 0; i < lzw_encoded_bytes_expected; ++i) { - image->lzw_encoded_bytes.append(buffer[i]); - } + auto const lzw_subblock = TRY(image->lzw_encoded_bytes.get_bytes_for_writing(lzw_encoded_bytes_expected)); + TRY(context.stream.read_until_filled(lzw_subblock)); } current_image = make();