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

Allocate less in GetIPEndPoint #1004

Merged
merged 1 commit into from
Jul 21, 2016
Merged
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
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: don't remove blank line after block

}

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