ipnetwork icon indicating copy to clipboard operation
ipnetwork copied to clipboard

Performance considerations

Open maettu-this opened this issue 3 years ago • 0 comments

Hi Luc,

https://github.com/lduchosal/ipnetwork/blob/master/src/System.Net.IPNetwork/IPNetwork.cs public bool Contains(IPAddress ipaddress) each time recreates CreateBroadcast(ref uintNetwork, this._netmask, this._family);. All input are fields. Why not recreate the broadcast address only when any of the input changes?

Background: For my piece of open source software I intend to call Contains() on every UDP packet received, i.e. very often. In such a case of course you don't want to spend more time than really needed.

Note https://stackoverflow.com/questions/1499269/how-to-check-if-an-ip-address-is-within-a-particular-subnet where an alternative approach for the operation I need is suggested. However, I think having an IPNetwork object should be better performing. Still, I think it could be useful to provide a similar static signature with your class. For infrequent use calling something like public static bool IPNetwork.Contains(string network, IPAddress address) sounds handy.

Best regards, Matthias

PS: By when do you intend to release the next version? I am desperatly looking forward for the release of the IPNetwork(IPAddress ipaddress, byte cidr) constructor. Only being able to create object by calling Parse(...) is quite limiting...

maettu-this avatar Sep 14 '22 20:09 maettu-this