Skip to content

Commit 32f6777

Browse files
committed
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.
1 parent e20e47f commit 32f6777

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: src/ImageSharp/Formats/Webp/BitWriter/Vp8BitWriter.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ private void CodeIntraModes()
592592

593593
private void WriteVp8Header(Stream stream, uint size)
594594
{
595-
Span<byte> buf = stackalloc byte[WebpConstants.TagSize];
595+
Span<byte> buf = byte[WebpConstants.TagSize];
596596
BinaryPrimitives.WriteUInt32BigEndian(buf, (uint)WebpChunkType.Vp8);
597597
stream.Write(buf);
598598
BinaryPrimitives.WriteUInt32LittleEndian(buf, size);
@@ -604,7 +604,7 @@ private void WriteFrameHeader(Stream stream, uint size0)
604604
uint profile = 0;
605605
int width = this.enc.Width;
606606
int height = this.enc.Height;
607-
byte[] vp8FrameHeader = new byte[WebpConstants.Vp8FrameHeaderSize];
607+
Span<byte> vp8FrameHeader = stackalloc byte[WebpConstants.Vp8FrameHeaderSize];
608608

609609
// Paragraph 9.1.
610610
uint bits = 0 // keyframe (1b)

0 commit comments

Comments
 (0)