Browse Source

Refactor buffer allocation in Vp8BitWriter.cs to use Span<byte> instead of byte[] in WriteFrameHeader.

This change enhances memory efficiency by reducing heap allocations and leveraging stack allocation for better performance.
pull/2905/head
Paulo Morgado 1 year ago
parent
commit
b2c03c1799
  1. 2
      src/ImageSharp/Formats/Webp/BitWriter/Vp8BitWriter.cs

2
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<byte> vp8FrameHeader = stackalloc byte[WebpConstants.Vp8FrameHeaderSize];
// Paragraph 9.1.
uint bits = 0 // keyframe (1b)

Loading…
Cancel
Save