From b60ce906e3b5678359a71c0a1ecfd82216d52de0 Mon Sep 17 00:00:00 2001 From: Ynse Hoornenborg Date: Thu, 28 Dec 2023 22:59:31 +0100 Subject: [PATCH] Move to Memory namespace --- .../{Formats/Heic => Memory}/AutoExpandingMemory.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) rename src/ImageSharp/{Formats/Heic => Memory}/AutoExpandingMemory.cs (87%) diff --git a/src/ImageSharp/Formats/Heic/AutoExpandingMemory.cs b/src/ImageSharp/Memory/AutoExpandingMemory.cs similarity index 87% rename from src/ImageSharp/Formats/Heic/AutoExpandingMemory.cs rename to src/ImageSharp/Memory/AutoExpandingMemory.cs index 376654a205..7d118e05bc 100644 --- a/src/ImageSharp/Formats/Heic/AutoExpandingMemory.cs +++ b/src/ImageSharp/Memory/AutoExpandingMemory.cs @@ -3,7 +3,7 @@ using System.Buffers; -namespace SixLabors.ImageSharp.Formats.Heic; +namespace SixLabors.ImageSharp.Memory; /// /// Memory class that will expand dynamically when full. @@ -11,6 +11,7 @@ namespace SixLabors.ImageSharp.Formats.Heic; internal sealed class AutoExpandingMemory : IDisposable where T : unmanaged { + private const int IncreaseFactor = 5; private readonly Configuration configuration; private IMemoryOwner allocation; @@ -32,7 +33,7 @@ internal sealed class AutoExpandingMemory : IDisposable public Span GetSpan(int offset, int requestedSize) { - Guard.MustBeGreaterThan(offset, 0, nameof(offset)); + Guard.MustBeGreaterThanOrEqualTo(offset, 0, nameof(offset)); Guard.MustBeGreaterThan(requestedSize, 0, nameof(requestedSize)); this.EnsureCapacity(offset + requestedSize); @@ -45,7 +46,7 @@ internal sealed class AutoExpandingMemory : IDisposable { if (requestedSize > this.allocation.Memory.Length) { - int newSize = requestedSize + (requestedSize / 5); + int newSize = requestedSize + (requestedSize / IncreaseFactor); IMemoryOwner newAllocation = this.configuration.MemoryAllocator.Allocate(newSize); this.allocation.Memory.CopyTo(newAllocation.Memory); this.allocation.Dispose();