From 911b20ebb5898ce111e7c31cd1801e2534e2a3c6 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Wed, 27 Apr 2022 11:19:20 +0200 Subject: [PATCH] Avoid byte[] allocation for IPAddressUtil.IsMulticast Ping.RawSocket his its own inline implementaion of this, maybe this should be consolidated somewhere? src/libraries/System.Net.Ping/src/System/Net/NetworkInformation/Ping.RawSocket.cs L101 --- .../src/System/Net/NetworkInformation/IPAddressUtil.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPAddressUtil.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPAddressUtil.cs index 6f7081026cb86f..c2e776a07bee0c 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPAddressUtil.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/IPAddressUtil.cs @@ -20,7 +20,9 @@ public static bool IsMulticast(IPAddress address) } else { - byte firstByte = address.GetAddressBytes()[0]; +#pragma warning disable CS0618 // using Obsolete Address API because it's the more efficient option in this case + byte firstByte = (byte)address.Address; +#pragma warning restore CS0618 return firstByte >= 224 && firstByte <= 239; } }