From f7d9d37a6bf327204c210609cdb2cff3d9e8c774 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Mon, 16 Aug 2021 22:49:33 +0200 Subject: [PATCH] cleanup naming in UniformUnmanagedMemoryPool --- .../Internals/UniformUnmanagedMemoryPool.cs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/ImageSharp/Memory/Allocators/Internals/UniformUnmanagedMemoryPool.cs b/src/ImageSharp/Memory/Allocators/Internals/UniformUnmanagedMemoryPool.cs index 97599b5ab..cfb0b3eb5 100644 --- a/src/ImageSharp/Memory/Allocators/Internals/UniformUnmanagedMemoryPool.cs +++ b/src/ImageSharp/Memory/Allocators/Internals/UniformUnmanagedMemoryPool.cs @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.Memory.Internals return null; } - UnmanagedMemoryHandle array; + UnmanagedMemoryHandle buffer; lock (buffersLocal) { @@ -72,21 +72,21 @@ namespace SixLabors.ImageSharp.Memory.Internals return null; } - array = buffersLocal[this.index]; + buffer = buffersLocal[this.index]; buffersLocal[this.index++] = null; } - if (array == null) + if (buffer == null) { - array = new UnmanagedMemoryHandle(this.BufferLength); + buffer = UnmanagedMemoryHandle.Allocate(this.BufferLength); } if (allocationOptions.Has(AllocationOptions.Clean)) { - this.GetSpan(array).Clear(); + this.GetSpan(buffer).Clear(); } - return array; + return buffer; } public UnmanagedMemoryHandle[] Rent(int bufferCount, AllocationOptions allocationOptions = AllocationOptions.None) @@ -120,7 +120,7 @@ namespace SixLabors.ImageSharp.Memory.Internals { if (result[i] == null) { - result[i] = new UnmanagedMemoryHandle(this.BufferLength); + result[i] = UnmanagedMemoryHandle.Allocate(this.BufferLength); } if (allocationOptions.Has(AllocationOptions.Clean)) @@ -152,7 +152,7 @@ namespace SixLabors.ImageSharp.Memory.Internals if (this.index == 0) { - ThrowReturnedMoreArraysThanRented(); // DEBUG-only exception + ThrowReturnedMoreBuffersThanRented(); // DEBUG-only exception buffer.Dispose(); return; } @@ -181,7 +181,7 @@ namespace SixLabors.ImageSharp.Memory.Internals if (this.index - buffers.Length + 1 <= 0) { - ThrowReturnedMoreArraysThanRented(); + ThrowReturnedMoreBuffersThanRented(); DisposeAll(buffers); return; } @@ -216,8 +216,8 @@ namespace SixLabors.ImageSharp.Memory.Internals // This indicates a bug in the library, however Return() might be called from a finalizer, // therefore we should never throw here in production. [Conditional("DEBUG")] - private static void ThrowReturnedMoreArraysThanRented() => - throw new InvalidMemoryOperationException("Returned more arrays then rented"); + private static void ThrowReturnedMoreBuffersThanRented() => + throw new InvalidMemoryOperationException("Returned more buffers then rented"); private static void TimerCallback(WeakReference weakPoolRef) { @@ -271,18 +271,18 @@ namespace SixLabors.ImageSharp.Memory.Internals return true; } - private bool TrimLowPressure(UnmanagedMemoryHandle[] arraysLocal) + private bool TrimLowPressure(UnmanagedMemoryHandle[] buffersLocal) { - lock (arraysLocal) + lock (buffersLocal) { if (this.buffers == null) { return false; } - // Count the arrays in the pool: + // Count the buffers in the pool: int retainedCount = 0; - for (int i = this.index; i < arraysLocal.Length && arraysLocal[i] != null; i++) + for (int i = this.index; i < buffersLocal.Length && buffersLocal[i] != null; i++) { retainedCount++; } @@ -293,8 +293,8 @@ namespace SixLabors.ImageSharp.Memory.Internals int trimStop = this.index + retainedCount - trimCount; for (int i = trimStart; i >= trimStop; i--) { - arraysLocal[i].Dispose(); - arraysLocal[i] = null; + buffersLocal[i].Dispose(); + buffersLocal[i] = null; } this.lastTrimTimestamp = Stopwatch.ElapsedMilliseconds;