Skip to content

Commit 8f74184

Browse files
committed
Fixed inconsistency with ReadOnlySpan2D<T>.Slice parameters
1 parent c31e049 commit 8f74184

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

Microsoft.Toolkit.HighPerformance/Memory/ReadOnlySpan2D{T}.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -803,15 +803,15 @@ public ref T DangerousGetReferenceAt(int i, int j)
803803
/// </summary>
804804
/// <param name="row">The target row to map within the current instance.</param>
805805
/// <param name="column">The target column to map within the current instance.</param>
806-
/// <param name="width">The width to map within the current instance.</param>
807806
/// <param name="height">The height to map within the current instance.</param>
807+
/// <param name="width">The width to map within the current instance.</param>
808808
/// <exception cref="ArgumentException">
809809
/// Thrown when either <paramref name="height"/>, <paramref name="width"/> or <paramref name="height"/>
810810
/// are negative or not within the bounds that are valid for the current instance.
811811
/// </exception>
812812
/// <returns>A new <see cref="ReadOnlySpan2D{T}"/> instance representing a slice of the current one.</returns>
813813
[Pure]
814-
public ReadOnlySpan2D<T> Slice(int row, int column, int width, int height)
814+
public ReadOnlySpan2D<T> Slice(int row, int column, int height, int width)
815815
{
816816
if ((uint)row >= Height)
817817
{
@@ -823,14 +823,14 @@ public ReadOnlySpan2D<T> Slice(int row, int column, int width, int height)
823823
ThrowHelper.ThrowArgumentOutOfRangeExceptionForColumn();
824824
}
825825

826-
if ((uint)width > (this.width - column))
826+
if ((uint)height > (Height - row))
827827
{
828-
ThrowHelper.ThrowArgumentOutOfRangeExceptionForWidth();
828+
ThrowHelper.ThrowArgumentOutOfRangeExceptionForHeight();
829829
}
830830

831-
if ((uint)height > (Height - row))
831+
if ((uint)width > (this.width - column))
832832
{
833-
ThrowHelper.ThrowArgumentOutOfRangeExceptionForHeight();
833+
ThrowHelper.ThrowArgumentOutOfRangeExceptionForWidth();
834834
}
835835

836836
nint shift = ((nint)(uint)this.stride * (nint)(uint)row) + (nint)(uint)column;

UnitTests/UnitTests.HighPerformance.Shared/Memory/Test_ReadOnlySpan2D{T}.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ public void Test_ReadOnlySpan2DT_Slice_1()
412412

413413
ReadOnlySpan2D<int> span2d = new ReadOnlySpan2D<int>(array);
414414

415-
ReadOnlySpan2D<int> slice1 = span2d.Slice(1, 1, 2, 1);
415+
ReadOnlySpan2D<int> slice1 = span2d.Slice(1, 1, 1, 2);
416416

417417
Assert.AreEqual(slice1.Length, 2);
418418
Assert.AreEqual(slice1.Height, 1);
@@ -431,11 +431,11 @@ public void Test_ReadOnlySpan2DT_Slice_1()
431431

432432
Assert.ThrowsException<ArgumentOutOfRangeException>(() => new ReadOnlySpan2D<int>(array).Slice(-1, 1, 1, 1));
433433
Assert.ThrowsException<ArgumentOutOfRangeException>(() => new ReadOnlySpan2D<int>(array).Slice(1, -1, 1, 1));
434-
Assert.ThrowsException<ArgumentOutOfRangeException>(() => new ReadOnlySpan2D<int>(array).Slice(1, 1, -1, 1));
435434
Assert.ThrowsException<ArgumentOutOfRangeException>(() => new ReadOnlySpan2D<int>(array).Slice(1, 1, 1, -1));
435+
Assert.ThrowsException<ArgumentOutOfRangeException>(() => new ReadOnlySpan2D<int>(array).Slice(1, 1, -1, 1));
436436
Assert.ThrowsException<ArgumentOutOfRangeException>(() => new ReadOnlySpan2D<int>(array).Slice(10, 1, 1, 1));
437-
Assert.ThrowsException<ArgumentOutOfRangeException>(() => new ReadOnlySpan2D<int>(array).Slice(1, 12, 12, 1));
438-
Assert.ThrowsException<ArgumentOutOfRangeException>(() => new ReadOnlySpan2D<int>(array).Slice(1, 1, 1, 55));
437+
Assert.ThrowsException<ArgumentOutOfRangeException>(() => new ReadOnlySpan2D<int>(array).Slice(1, 12, 1, 12));
438+
Assert.ThrowsException<ArgumentOutOfRangeException>(() => new ReadOnlySpan2D<int>(array).Slice(1, 1, 55, 1));
439439
}
440440

441441
[TestCategory("ReadOnlySpan2DT")]
@@ -458,7 +458,7 @@ public void Test_ReadOnlySpan2DT_Slice_2()
458458
Assert.AreEqual(slice1[0, 0], 1);
459459
Assert.AreEqual(slice1[1, 1], 5);
460460

461-
ReadOnlySpan2D<int> slice2 = slice1.Slice(1, 0, 2, 1);
461+
ReadOnlySpan2D<int> slice2 = slice1.Slice(1, 0, 1, 2);
462462

463463
Assert.AreEqual(slice2.Length, 2);
464464
Assert.AreEqual(slice2.Height, 1);

0 commit comments

Comments
 (0)