From b2c03c1799b2253468eb2245a1c3f854ca47a17a Mon Sep 17 00:00:00 2001 From: Paulo Morgado <470455+paulomorgado@users.noreply.github.com> Date: Wed, 26 Mar 2025 12:17:25 +0000 Subject: [PATCH] Refactor buffer allocation in Vp8BitWriter.cs to use Span instead of byte[] in WriteFrameHeader. This change enhances memory efficiency by reducing heap allocations and leveraging stack allocation for better performance. --- src/ImageSharp/Formats/Webp/BitWriter/Vp8BitWriter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageSharp/Formats/Webp/BitWriter/Vp8BitWriter.cs b/src/ImageSharp/Formats/Webp/BitWriter/Vp8BitWriter.cs index 81530706d6..505f54312f 100644 --- a/src/ImageSharp/Formats/Webp/BitWriter/Vp8BitWriter.cs +++ b/src/ImageSharp/Formats/Webp/BitWriter/Vp8BitWriter.cs @@ -604,7 +604,7 @@ internal class Vp8BitWriter : BitWriterBase uint profile = 0; int width = this.enc.Width; int height = this.enc.Height; - byte[] vp8FrameHeader = new byte[WebpConstants.Vp8FrameHeaderSize]; + Span vp8FrameHeader = stackalloc byte[WebpConstants.Vp8FrameHeaderSize]; // Paragraph 9.1. uint bits = 0 // keyframe (1b)