Skip to content

Commit 1ecb4be

Browse files
committed
Avoid unnecessary sign-extension
1 parent 13a2088 commit 1ecb4be

File tree

1 file changed

+2
-2
lines changed
  • src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices

1 file changed

+2
-2
lines changed

src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/SafeBuffer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public void ReadSpan<T>(ulong byteOffset, Span<T> buffer)
246246
ref T structure = ref MemoryMarshal.GetReference(buffer);
247247
for (int i = 0; i < buffer.Length; i++)
248248
{
249-
Unsafe.Add(ref structure, i) = Unsafe.ReadUnaligned<T>(ptr + alignedSizeofT * i);
249+
Unsafe.Add(ref structure, (nint)(uint)i) = Unsafe.ReadUnaligned<T>(ptr + (nuint)alignedSizeofT * (uint)i);
250250
}
251251
}
252252
finally
@@ -335,7 +335,7 @@ public void WriteSpan<T>(ulong byteOffset, ReadOnlySpan<T> data)
335335
ref T structure = ref MemoryMarshal.GetReference(data);
336336
for (int i = 0; i < data.Length; i++)
337337
{
338-
Unsafe.WriteUnaligned(ptr + alignedSizeofT * i, Unsafe.Add(ref structure, i));
338+
Unsafe.WriteUnaligned(ptr + (nuint)alignedSizeofT * (uint)i, Unsafe.Add(ref structure, (nint)(uint)i));
339339
}
340340
}
341341
finally

0 commit comments

Comments
 (0)