equatable icon indicating copy to clipboard operation
equatable copied to clipboard

Use Dart 2.14's new hashing functions

Open hacker1024 opened this issue 2 years ago • 2 comments

Dart 2.14 adds new hashing methods like Object.hash (uses optional arguments for up to 20 objects) and Object.hashAll (uses a list for a large or variable number of objects).

The reasoning behind this addition to the language can be found at https://github.com/dart-lang/sdk/issues/11617. Also see https://dart-review.googlesource.com/c/sdk/+/73360.

Using the built-in hashing functions would allow this package to have a smaller footprint and fit in with everything else if the Dart maintainers ever decide to change or optimise the hashing algorithm.

hacker1024 avatar Oct 29 '21 05:10 hacker1024

Hi @hacker1024 👋 Thanks for opening an issue!

I’m aware of Object.hash and Object.hashAll however last time I checked replacing the current implementation with Object.hashAll breaks the existing unit test suite.

I’ll take another look in the next week but if you’d like feel free to open a pull request. Thanks!

felangel avatar Oct 29 '21 12:10 felangel

I've just had a go at implementing this, but it's more complicated than I initially expected due to the recursive collection hashing functionality.

I have a question: Why not use _equality's hash method in mapPropsToHashCode? It seems to do the same thing as the existing implementation, although I'm not sure if it uses the same algorithm.

hacker1024 avatar Oct 30 '21 12:10 hacker1024

I'm closing this for now as Object.hashAll isn't functionally equivalent to the current implementation.

felangel avatar Oct 14 '23 23:10 felangel