From 7b7e2889ce3e0d55fc913a42b8fa7c153e4a8a33 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 21 Jul 2016 12:17:55 -0700 Subject: [PATCH] Allocate less in GetIPEndPoint (#1004) --- .../Internal/Networking/SockAddr.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs index d2d14774ef..a5d5338bab 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Internal/Networking/SockAddr.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking _field3 = _field0 = _field1 = _field2 = _field3 = 0; } - public IPEndPoint GetIPEndPoint() + public unsafe IPEndPoint GetIPEndPoint() { // The bytes are represented in network byte order. // @@ -84,14 +84,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Networking 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);