diff --git a/HPPH/Images/Image.cs b/HPPH/Images/Image.cs index 8820d42..171ac44 100644 --- a/HPPH/Images/Image.cs +++ b/HPPH/Images/Image.cs @@ -124,7 +124,7 @@ public sealed class Image : IImage, IEquatable> if (stride < width) throw new ArgumentException("Stride can't be smaller than width."); if (buffer.Length < (height * stride)) throw new ArgumentException("Not enough data in the buffer."); - byte[] data = new byte[buffer.Length]; + byte[] data = GC.AllocateUninitializedArray(buffer.Length); buffer.CopyTo(data); return new Image(data, 0, 0, width, height, stride); } @@ -152,7 +152,7 @@ public sealed class Image : IImage, IEquatable> else { byte[] data = ToRawArray(); - byte[] target = new byte[Width * Height * targetBpp]; + byte[] target = GC.AllocateUninitializedArray(Width * Height * targetBpp); MemoryMarshal.Cast(data.AsSpan()).Convert(MemoryMarshal.Cast(target)); return new Image(target, 0, 0, Width, Height, Width * targetBpp); } @@ -180,7 +180,7 @@ public sealed class Image : IImage, IEquatable> /// public byte[] ToRawArray() { - byte[] array = new byte[SizeInBytes]; + byte[] array = GC.AllocateUninitializedArray(SizeInBytes); CopyTo(array); return array; } @@ -188,7 +188,7 @@ public sealed class Image : IImage, IEquatable> /// public T[] ToArray() { - T[] colors = new T[Width * Height]; + T[] colors = GC.AllocateUninitializedArray(Width * Height); CopyTo(colors); return colors; } diff --git a/HPPH/Images/ImageColumn.cs b/HPPH/Images/ImageColumn.cs index 0e551b5..30e127e 100644 --- a/HPPH/Images/ImageColumn.cs +++ b/HPPH/Images/ImageColumn.cs @@ -64,7 +64,7 @@ public readonly ref struct ImageColumn public T[] ToArray() { - T[] array = new T[Length]; + T[] array = GC.AllocateUninitializedArray(Length); CopyTo(array); return array; } diff --git a/HPPH/Images/ImageRow.cs b/HPPH/Images/ImageRow.cs index d48294f..325c245 100644 --- a/HPPH/Images/ImageRow.cs +++ b/HPPH/Images/ImageRow.cs @@ -62,10 +62,11 @@ public readonly ref struct ImageRow public T[] ToArray() { - T[] array = new T[Length]; + T[] array = GC.AllocateUninitializedArray(Length); CopyTo(array); return array; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public ImageRowEnumerator GetEnumerator() => new(this); diff --git a/HPPH/Images/RefImage.cs b/HPPH/Images/RefImage.cs index 2b193e6..68aefe7 100644 --- a/HPPH/Images/RefImage.cs +++ b/HPPH/Images/RefImage.cs @@ -128,7 +128,7 @@ public readonly ref struct RefImage /// The new array containing the data of this . public T[] ToArray() { - T[] array = new T[Width * Height]; + T[] array = GC.AllocateUninitializedArray(Width * Height); CopyTo(array); return array; } diff --git a/HPPH/PixelHelper.Convert.cs b/HPPH/PixelHelper.Convert.cs index 43f1e5b..bdf6ab4 100644 --- a/HPPH/PixelHelper.Convert.cs +++ b/HPPH/PixelHelper.Convert.cs @@ -38,7 +38,7 @@ public static unsafe partial class PixelHelper { if (colors == null) throw new ArgumentNullException(nameof(colors)); - TTarget[] buffer = new TTarget[colors.Length]; + TTarget[] buffer = GC.AllocateUninitializedArray(colors.Length); Convert(colors, buffer.AsSpan()); return buffer; } @@ -49,7 +49,7 @@ public static unsafe partial class PixelHelper { if (colors == null) throw new ArgumentNullException(nameof(colors)); - TTarget[] buffer = new TTarget[colors.Length]; + TTarget[] buffer = GC.AllocateUninitializedArray(colors.Length); Convert(colors, buffer.AsSpan()); return buffer; }