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

Commit

Permalink
Use Span to drop byte[1] allocations (dotnet/coreclr#15680)
Browse files Browse the repository at this point in the history
Signed-off-by: dotnet-bot-corefx-mirror <[email protected]>
  • Loading branch information
benaadams authored and dotnet-bot committed Jan 13, 2018
1 parent fc5f91c commit e5de095
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/Common/src/CoreLib/System/IO/PinnedBufferMemoryStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,12 @@ internal PinnedBufferMemoryStream(byte[] array)
{
Debug.Assert(array != null, "Array can't be null");

int len = array.Length;
// Handle 0 length byte arrays specially.
if (len == 0)
{
array = new byte[1];
len = 0;
}

_array = array;
_pinningHandle = GCHandle.Alloc(array, GCHandleType.Pinned);
// Now the byte[] is pinned for the lifetime of this instance.
// But I also need to get a pointer to that block of memory...
fixed (byte* ptr = &_array[0])
int len = array.Length;
fixed (byte* ptr = &MemoryMarshal.GetReference((Span<byte>)array))
Initialize(ptr, len, len, FileAccess.Read);
}

Expand Down

0 comments on commit e5de095

Please sign in to comment.