From f63f85aaef42fbe31f14239ee2cbc12482d4d958 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 19 Jun 2017 02:08:24 +1000 Subject: [PATCH] Use buffer --- .../Formats/Jpeg/Port/JpegDecoderCore.cs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/Port/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/Port/JpegDecoderCore.cs index 3d36d61d9..300cb7aef 100644 --- a/src/ImageSharp/Formats/Jpeg/Port/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/Port/JpegDecoderCore.cs @@ -362,26 +362,17 @@ namespace ImageSharp.Formats.Jpeg.Port codeLengthSum += codeLengths[j] = huffmanData[o++]; } + // TODO: Pooling? short[] huffmanValues = new short[codeLengthSum]; - - byte[] values = null; - try + using (var values = new Buffer(256)) { - values = ArrayPool.Shared.Rent(256); - this.InputStream.Read(values, 0, codeLengthSum); + this.InputStream.Read(values.Array, 0, codeLengthSum); for (int j = 0; j < codeLengthSum; j++) { huffmanValues[j] = values[o++]; } } - finally - { - if (values != null) - { - ArrayPool.Shared.Return(values); - } - } i += 17 + codeLengthSum;