Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
Allocate less in GetIPEndPoint (#1004)
Browse files Browse the repository at this point in the history
  • Loading branch information
pakrym authored Jul 21, 2016
1 parent 3078f49 commit 7b7e288
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public SockAddr(long ignored)
_field3 = _field0 = _field1 = _field2 = _field3 = 0;
}

public IPEndPoint GetIPEndPoint()
public unsafe IPEndPoint GetIPEndPoint()
{
// The bytes are represented in network byte order.
//
Expand Down Expand Up @@ -84,14 +84,11 @@ public IPEndPoint GetIPEndPoint()
else
{
// otherwise IPv6
var bytes1 = BitConverter.GetBytes(_field1);
var bytes2 = BitConverter.GetBytes(_field2);

var bytes = new byte[16];
for (int i = 0; i < 8; ++i)
fixed (byte* b = bytes)
{
bytes[i] = bytes1[i];
bytes[i + 8] = bytes2[i];
*((long*)b) = _field1;
*((long*)(b + 8)) = _field2;
}

return new IPEndPoint(new IPAddress(bytes), port);
Expand Down

0 comments on commit 7b7e288

Please sign in to comment.