Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Remove allocations from Marvin.GenerateSeed #32661

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Common/src/System/Marvin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ private static ulong GenerateSeed()
{
using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
{
var bytes = new byte[sizeof(ulong)];
Span<byte> bytes = stackalloc byte[sizeof(ulong)];
rng.GetBytes(bytes);
return BitConverter.ToUInt64(bytes, 0);
return MemoryMarshal.Cast<byte, ulong>(bytes)[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not portable to platforms with strong alignment requirements. This should be MemoryMarshal.Read<ulong>(bytes) instead.

}
}
}
Expand Down