ENet-CSharp icon indicating copy to clipboard operation
ENet-CSharp copied to clipboard

Peer should impliment IEquatable<T> interface.

Open rybakatchya opened this issue 2 years ago • 4 comments

Right now if you have peer in a list and call List.Contains(Peer) it will cause GC allocations. Implementing IEquatable<T> on the Peer struct will resolve this issue. See https://medium.com/@semuserable/c-journey-into-struct-equality-comparison-deep-dive-9693f74562f1

rybakatchya avatar May 22 '22 11:05 rybakatchya

Would putting the peers into a Dictionary<uint PeerID, Peer Peer> solve this? Is there any reason you need to have the Peers in a List like that?

valkyrienyanko avatar May 23 '22 04:05 valkyrienyanko

I could do that, but the same problem will happen if you use Dictionary.ContainsValue. Really no reason to not implement IEquatable and I have already done so locally.

rybakatchya avatar May 23 '22 05:05 rybakatchya

I have no objections to this, do you want to do a PR and I'll merge it in?

SoftwareGuy avatar May 23 '22 07:05 SoftwareGuy

I'm curious as to why you need to do Dictionary.ContainsValue as suppose to Dictionary.ContainsKey

valkyrienyanko avatar May 23 '22 17:05 valkyrienyanko