Skip to content

Commit e168ae6

Browse files
committed
Use Span in GetHTreeGroupForPos to avoid allocations
1 parent d3f3eec commit e168ae6

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public void DecodeImageData(Vp8LDecoder decoder, Span<uint> pixelData)
218218
ColorCache colorCache = decoder.Metadata.ColorCache;
219219
int colorCacheLimit = lenCodeLimit + colorCacheSize;
220220
int mask = decoder.Metadata.HuffmanMask;
221-
HTreeGroup[] hTreeGroup = GetHTreeGroupForPos(decoder.Metadata, col, row);
221+
Span<HTreeGroup> hTreeGroup = GetHTreeGroupForPos(decoder.Metadata, col, row);
222222

223223
int totalPixels = width * height;
224224
int decodedPixels = 0;
@@ -731,7 +731,7 @@ public void DecodeAlphaData(AlphaDecoder dec)
731731
int lastRow = height;
732732
const int lenCodeLimit = WebpConstants.NumLiteralCodes + WebpConstants.NumLengthCodes;
733733
int mask = hdr.HuffmanMask;
734-
HTreeGroup[] htreeGroup = pos < last ? GetHTreeGroupForPos(hdr, col, row) : null;
734+
Span<HTreeGroup> htreeGroup = pos < last ? GetHTreeGroupForPos(hdr, col, row) : null;
735735
while (!this.bitReader.Eos && pos < last)
736736
{
737737
// Only update when changing tile.
@@ -815,7 +815,7 @@ private void UpdateDecoder(Vp8LDecoder decoder, int width, int height)
815815
decoder.Metadata.HuffmanMask = numBits == 0 ? ~0 : (1 << numBits) - 1;
816816
}
817817

818-
private uint ReadPackedSymbols(HTreeGroup[] group, Span<uint> pixelData, int decodedPixels)
818+
private uint ReadPackedSymbols(Span<HTreeGroup> group, Span<uint> pixelData, int decodedPixels)
819819
{
820820
uint val = (uint)(this.bitReader.PrefetchBits() & (HuffmanUtils.HuffmanPackedTableSize - 1));
821821
HuffmanCode code = group[0].PackedTable[val];
@@ -895,10 +895,10 @@ private int GetCopyDistance(int distanceSymbol)
895895
}
896896

897897
[MethodImpl(InliningOptions.ShortMethod)]
898-
private static HTreeGroup[] GetHTreeGroupForPos(Vp8LMetadata metadata, int x, int y)
898+
private static Span<HTreeGroup> GetHTreeGroupForPos(Vp8LMetadata metadata, int x, int y)
899899
{
900900
uint metaIndex = GetMetaIndex(metadata.HuffmanImage, metadata.HuffmanXSize, metadata.HuffmanSubSampleBits, x, y);
901-
return metadata.HTreeGroups.AsSpan((int)metaIndex).ToArray();
901+
return metadata.HTreeGroups.AsSpan((int)metaIndex);
902902
}
903903

904904
[MethodImpl(InliningOptions.ShortMethod)]

0 commit comments

Comments
 (0)