Skip to content

Commit 83dd209

Browse files
committed
Fix mutability of ReadOnlySpan2D<T>.GetPinnableReference()
1 parent 1e622fb commit 83dd209

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/CommunityToolkit.HighPerformance/Memory/ReadOnlySpan2D{T}.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -780,14 +780,14 @@ public bool TryCopyTo(Span2D<T> destination)
780780
/// <returns>A reference to the 0th element, or a <see langword="null"/> reference.</returns>
781781
[MethodImpl(MethodImplOptions.AggressiveInlining)]
782782
[EditorBrowsable(EditorBrowsableState.Never)]
783-
public unsafe ref T GetPinnableReference()
783+
public unsafe ref readonly T GetPinnableReference()
784784
{
785-
ref T r0 = ref Unsafe.AsRef<T>(null);
785+
ref readonly T r0 = ref Unsafe.AsRef<T>(null);
786786

787787
if (Length != 0)
788788
{
789789
#if NET7_0_OR_GREATER
790-
r0 = ref Unsafe.AsRef(in this.reference);
790+
r0 = ref this.reference;
791791
#elif NETSTANDARD2_1_OR_GREATER
792792
r0 = ref MemoryMarshal.GetReference(this.span);
793793
#else

tests/CommunityToolkit.HighPerformance.UnitTests/Memory/Test_ReadOnlySpan2D{T}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public unsafe void Test_ReadOnlySpan2DT_GetPinnableReference()
351351
{
352352
Assert.IsTrue(Unsafe.AreSame(
353353
ref Unsafe.AsRef<int>(null),
354-
ref ReadOnlySpan2D<int>.Empty.GetPinnableReference()));
354+
ref Unsafe.AsRef(in ReadOnlySpan2D<int>.Empty.GetPinnableReference())));
355355

356356
int[,] array =
357357
{
@@ -361,7 +361,7 @@ ref Unsafe.AsRef<int>(null),
361361

362362
ReadOnlySpan2D<int> span2d = new(array);
363363

364-
ref int r0 = ref span2d.GetPinnableReference();
364+
ref int r0 = ref Unsafe.AsRef(in span2d.GetPinnableReference());
365365

366366
Assert.IsTrue(Unsafe.AreSame(ref r0, ref array[0, 0]));
367367
}

0 commit comments

Comments
 (0)