Repository navigation
Support for nullable arrays and hash code calculation - #1521
Conversation
Also cleaned up some value comparer logic which wasn't getting used at all. Closes npgsql#1025
Co-authored-by: Yoh Deadfall <[email protected]>
Also implement array hash code calculation
|
Note: I've also implemented proper hash code calculation as part of this PR. |
YohDeadfall
left a comment
There was a problem hiding this comment.
Looks good, but can be simplified.
|
Merged via a3976bc |
|
@YohDeadfall fixed in fe63b36. Not super happy that a comparer gets allocated for each GetHashCode call, but it's only for nullable arrays and probably really doesn't matter. |
|
You don't need a new comparer, just some write it this way: foreach (var element in source)
if (element is null)
code.Add(element);
else
code.Add(element.Value, comparer);Internally it will fallback to foreach (var element in source)
code.Add(element is { } value ? comparer.GetHashCode(value) : 0);The last variant does the same thing as |
|
@YohDeadfall note that HashSet.Add doesn't accept a hash code as its parameter - it accepts a value on which it invokes GetHashCode. If we use the overload without an IEqualityComparer, that means that the default GetHashCode for the type gets invoked, instead of the one defined on the element's value comparer. |
|
Ah, it's private. Anyway the hash code of an |
|
But not all elements are int, right? This needs to work for arrays over arbitrary value types, and I'm trying to make sure that element's value comparer is always used, and not the type's GetHashCode. |
Also cleaned up some value comparer logic which wasn't getting used at all.
Closes #1025