Skip to content

Commit

Permalink
Avoid unnecessary sign-extension
Browse files Browse the repository at this point in the history
  • Loading branch information
xtqqczze committed Aug 8, 2024
1 parent 56671ea commit 3036449
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void ReadSpan<T>(ulong byteOffset, Span<T> buffer)
ref T structure = ref MemoryMarshal.GetReference(buffer);
for (int i = 0; i < buffer.Length; i++)
{
Unsafe.Add(ref structure, i) = Unsafe.ReadUnaligned<T>(ptr + alignedSizeofT * i);
Unsafe.Add(ref structure, (nint)(uint)i) = Unsafe.ReadUnaligned<T>(ptr + (nuint)alignedSizeofT * (uint)i);
}
}
finally
Expand Down Expand Up @@ -335,7 +335,7 @@ public void WriteSpan<T>(ulong byteOffset, ReadOnlySpan<T> data)
ref T structure = ref MemoryMarshal.GetReference(data);
for (int i = 0; i < data.Length; i++)
{
Unsafe.WriteUnaligned(ptr + alignedSizeofT * i, Unsafe.Add(ref structure, i));
Unsafe.WriteUnaligned(ptr + (nuint)alignedSizeofT * (uint)i, Unsafe.Add(ref structure, (nint)(uint)i));
}
}
finally
Expand Down

0 comments on commit 3036449

Please sign in to comment.