From 58a3a958bfc74f00a9d75011b8c7ebdc8c8bd65b Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sat, 12 Jun 2021 07:28:19 +1000 Subject: [PATCH] Just use ArrayPool.Shared --- .../Quantization/EuclideanPixelMap{TPixel}.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/ImageSharp/Processing/Processors/Quantization/EuclideanPixelMap{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/EuclideanPixelMap{TPixel}.cs index 89b6c315e..b2422c6d3 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/EuclideanPixelMap{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/EuclideanPixelMap{TPixel}.cs @@ -141,21 +141,20 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization private const int RgbShift = 8 - IndexBits; private const int AlphaShift = 8 - IndexAlphaBits; private const int TableLength = IndexCount * IndexCount * IndexCount * IndexAlphaCount; - private const int TableLengthBytes = TableLength * sizeof(short); private MemoryHandle tableHandle; - private readonly byte[] table; + private readonly short[] table; private readonly short* tablePointer; - private ColorDistanceCache(int length, int lengthBytes) + private ColorDistanceCache(int length) { - this.table = ArrayPool.Shared.Rent(lengthBytes); + this.table = ArrayPool.Shared.Rent(length); + this.table.AsSpan().Fill(-1); this.tableHandle = this.table.AsMemory().Pin(); - new Span(this.tableHandle.Pointer, length).Fill(-1); this.tablePointer = (short*)this.tableHandle.Pointer; } public static ColorDistanceCache Create() - => new ColorDistanceCache(TableLength, TableLengthBytes); + => new ColorDistanceCache(TableLength); [MethodImpl(InliningOptions.ShortMethod)] public void Add(Rgba32 rgba, byte index) @@ -195,7 +194,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization { if (this.table != null) { - ArrayPool.Shared.Return(this.table); + ArrayPool.Shared.Return(this.table); this.tableHandle.Dispose(); } }