From e66ecd8d99328ecdbfbaa084b023b0f5bb80a588 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 7 Sep 2020 12:11:13 +0200 Subject: [PATCH] Code refactoring, removed unnecessary extensions --- .../Extensions/SpanExtensions.cs | 92 ------------------- .../{Primitives => }/VectorExtensions.cs | 0 .../Buffers/Extensions/BufferExtensions.cs | 1 + .../ComputeSharp.Graphics.csproj | 2 +- src/ComputeSharp/ComputeSharp.nuspec | 2 +- 5 files changed, 3 insertions(+), 94 deletions(-) delete mode 100644 src/ComputeSharp.Core/Extensions/SpanExtensions.cs rename src/ComputeSharp.Core/Extensions/{Primitives => }/VectorExtensions.cs (100%) diff --git a/src/ComputeSharp.Core/Extensions/SpanExtensions.cs b/src/ComputeSharp.Core/Extensions/SpanExtensions.cs deleted file mode 100644 index 47bedcf8..00000000 --- a/src/ComputeSharp.Core/Extensions/SpanExtensions.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System.Diagnostics.Contracts; -using System.Runtime.InteropServices; - -namespace System -{ - /// - /// A that contains extension methods for the - /// - public static class SpanExtensions - { - /// - /// Creates a from a given 2D array - /// - /// The type of items in the input array - /// The input 2D array - /// A that maps all the items of the input array - [Pure] - public static Span AsSpan(this T[,] array) - { - ref T r0 = ref array[0, 0]; - - return MemoryMarshal.CreateSpan(ref r0, array.Length); - } - - /// - /// Creates a from a given 2D array - /// - /// The type of items in the input array - /// The input 2D array - /// The index of the initial row to map from the input array - /// A that maps the desired items of the input array - [Pure] - public static Span AsSpan(this T[,] array, Index startIndex) - { - int - rows = array.GetLength(0), - offset = startIndex.GetOffset(rows), - interval = rows - offset; - ref T r0 = ref array[offset, 0]; - - return MemoryMarshal.CreateSpan(ref r0, interval * array.GetLength(1)); - } - - /// - /// Creates a from a given 2D array - /// - /// The type of items in the input array - /// The input 2D array - /// The index of the initial row to map from the input array - /// A that maps the desired items of the input array - [Pure] - public static Span AsSpan(this T[,] array, int start) - { - int interval = array.GetLength(0) - start; - ref T r0 = ref array[start, 0]; - - return MemoryMarshal.CreateSpan(ref r0, interval * array.GetLength(1)); - } - - /// - /// Creates a from a given 2D array - /// - /// The type of items in the input array - /// The input 2D array - /// The index of the initial row to map from the input array - /// The number of rows to map from the input array - /// A that maps the desired items of the input array - [Pure] - public static Span AsSpan(this T[,] array, int start, int length) - { - ref T r0 = ref array[start, 0]; - - return MemoryMarshal.CreateSpan(ref r0, length * array.GetLength(1)); - } - - /// - /// Creates a from a given 2D array - /// - /// The type of items in the input array - /// The input 2D array - /// The range of rows to map from the input array - /// A that maps the desired items of the input array - [Pure] - public static Span AsSpan(this T[,] array, Range range) - { - var indices = range.GetOffsetAndLength(array.GetLength(0)); - ref T r0 = ref array[indices.Offset, 0]; - - return MemoryMarshal.CreateSpan(ref r0, indices.Length * array.GetLength(1)); - } - } -} diff --git a/src/ComputeSharp.Core/Extensions/Primitives/VectorExtensions.cs b/src/ComputeSharp.Core/Extensions/VectorExtensions.cs similarity index 100% rename from src/ComputeSharp.Core/Extensions/Primitives/VectorExtensions.cs rename to src/ComputeSharp.Core/Extensions/VectorExtensions.cs diff --git a/src/ComputeSharp.Graphics/Buffers/Extensions/BufferExtensions.cs b/src/ComputeSharp.Graphics/Buffers/Extensions/BufferExtensions.cs index 2c805394..e2ab354b 100644 --- a/src/ComputeSharp.Graphics/Buffers/Extensions/BufferExtensions.cs +++ b/src/ComputeSharp.Graphics/Buffers/Extensions/BufferExtensions.cs @@ -3,6 +3,7 @@ using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; using ComputeSharp.Graphics; using ComputeSharp.Graphics.Buffers.Abstract; +using Microsoft.Toolkit.HighPerformance.Extensions; namespace ComputeSharp { diff --git a/src/ComputeSharp.Graphics/ComputeSharp.Graphics.csproj b/src/ComputeSharp.Graphics/ComputeSharp.Graphics.csproj index 57c67582..a80c8d67 100644 --- a/src/ComputeSharp.Graphics/ComputeSharp.Graphics.csproj +++ b/src/ComputeSharp.Graphics/ComputeSharp.Graphics.csproj @@ -8,7 +8,7 @@ - + diff --git a/src/ComputeSharp/ComputeSharp.nuspec b/src/ComputeSharp/ComputeSharp.nuspec index d2c4be2c..3e632143 100644 --- a/src/ComputeSharp/ComputeSharp.nuspec +++ b/src/ComputeSharp/ComputeSharp.nuspec @@ -17,7 +17,7 @@ - +