* Improve ArraySegment's override of GetHashCode
* Use new implementation suggested by @VSadov
* Respond to PR feedback
* Remove the workaround for object.GetHashCode
* Respond to HashHelpers changes
* Fix compile errors.
Commit migrated from https://github.com/dotnet/coreclr/commit/
15ea0086a7e6f87e8237923684e100e3e1f44698
public override int GetHashCode()
{
- return null == _array
- ? 0
- : _array.GetHashCode() ^ _offset ^ _count;
+ if (_array == null)
+ {
+ return 0;
+ }
+
+ int hash = 5381;
+ hash = System.Numerics.Hashing.HashHelpers.Combine(hash, _offset);
+ hash = System.Numerics.Hashing.HashHelpers.Combine(hash, _count);
+
+ // The array hash is expected to be an evenly-distributed mixture of bits,
+ // so rather than adding the cost of another rotation we just xor it.
+ hash ^= _array.GetHashCode();
+ return hash;
}
public override bool Equals(Object obj)