From aaac1359b6ebe2bd3a3425d3dff55b9896333379 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Thu, 29 Dec 2016 03:07:13 +0100 Subject: [PATCH] removed CleanPooler --- .../Jpg/Components/Decoder/JpegPixelArea.cs | 7 +++-- .../Jpg/Components/Decoder/YCbCrImage.cs | 15 ++++++---- .../Formats/Jpg/Utils/CleanPooler.cs | 30 ------------------- 3 files changed, 14 insertions(+), 38 deletions(-) delete mode 100644 src/ImageSharp/Formats/Jpg/Utils/CleanPooler.cs diff --git a/src/ImageSharp/Formats/Jpg/Components/Decoder/JpegPixelArea.cs b/src/ImageSharp/Formats/Jpg/Components/Decoder/JpegPixelArea.cs index 29025dc64..916209289 100644 --- a/src/ImageSharp/Formats/Jpg/Components/Decoder/JpegPixelArea.cs +++ b/src/ImageSharp/Formats/Jpg/Components/Decoder/JpegPixelArea.cs @@ -4,6 +4,7 @@ // namespace ImageSharp.Formats.Jpg { + using System.Buffers; using System.Runtime.CompilerServices; /// @@ -75,7 +76,7 @@ namespace ImageSharp.Formats.Jpg public static JpegPixelArea CreatePooled(int width, int height) { int size = width * height; - var pixels = CleanPooler.RentCleanArray(size); + var pixels = BytePool.Rent(size); return new JpegPixelArea(pixels, width, 0); } @@ -89,10 +90,12 @@ namespace ImageSharp.Formats.Jpg return; } - CleanPooler.ReturnArray(this.Pixels); + BytePool.Return(this.Pixels); this.Pixels = null; } + private static ArrayPool BytePool => ArrayPool.Shared; + /// /// Gets the subarea that belongs to the Block8x8 defined by block indices /// diff --git a/src/ImageSharp/Formats/Jpg/Components/Decoder/YCbCrImage.cs b/src/ImageSharp/Formats/Jpg/Components/Decoder/YCbCrImage.cs index f842a295c..61308ee2f 100644 --- a/src/ImageSharp/Formats/Jpg/Components/Decoder/YCbCrImage.cs +++ b/src/ImageSharp/Formats/Jpg/Components/Decoder/YCbCrImage.cs @@ -5,6 +5,7 @@ namespace ImageSharp.Formats.Jpg { using System; + using System.Buffers; /// /// Represents an image made up of three color components (luminance, blue chroma, red chroma) @@ -21,9 +22,9 @@ namespace ImageSharp.Formats.Jpg { int cw, ch; YCbCrSize(width, height, ratio, out cw, out ch); - this.YPixels = CleanPooler.RentCleanArray(width * height); - this.CbPixels = CleanPooler.RentCleanArray(cw * ch); - this.CrPixels = CleanPooler.RentCleanArray(cw * ch); + this.YPixels = BytePool.Rent(width * height); + this.CbPixels = BytePool.Rent(cw * ch); + this.CrPixels = BytePool.Rent(cw * ch); this.Ratio = ratio; this.YOffset = 0; this.COffset = 0; @@ -67,6 +68,8 @@ namespace ImageSharp.Formats.Jpg YCbCrSubsampleRatio410, } + private static ArrayPool BytePool => ArrayPool.Shared; + /// /// Gets an offseted to the Cb channel /// @@ -128,9 +131,9 @@ namespace ImageSharp.Formats.Jpg /// public void Dispose() { - CleanPooler.ReturnArray(this.YPixels); - CleanPooler.ReturnArray(this.CrPixels); - CleanPooler.ReturnArray(this.CbPixels); + BytePool.Return(this.YPixels); + BytePool.Return(this.CrPixels); + BytePool.Return(this.CbPixels); } /// diff --git a/src/ImageSharp/Formats/Jpg/Utils/CleanPooler.cs b/src/ImageSharp/Formats/Jpg/Utils/CleanPooler.cs deleted file mode 100644 index 7369d658f..000000000 --- a/src/ImageSharp/Formats/Jpg/Utils/CleanPooler.cs +++ /dev/null @@ -1,30 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// -namespace ImageSharp.Formats -{ - using System.Buffers; - - /// - /// Wraps to always provide arrays initialized with default(T) - /// - /// The element type - internal class CleanPooler - { - private static readonly ArrayPool Pool = ArrayPool.Create(); - - /// - /// Rents a clean array - /// - /// The minimum array length - /// A clean array of T - public static T[] RentCleanArray(int minimumLength) => Pool.Rent(minimumLength); - - /// - /// Retursn array to the pool - /// - /// The array - public static void ReturnArray(T[] array) => Pool.Return(array, true); - } -} \ No newline at end of file