felangel / equatable

A Dart package that helps to implement value based equality without needing to explicitly override == and hashCode.
https://pub.dev/packages/equatable
MIT License
901 stars 100 forks source link

Use Dart 2.14's new hashing functions #129

Closed hacker1024 closed 9 months ago

hacker1024 commented 2 years ago

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.

felangel commented 2 years ago

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!

hacker1024 commented 2 years ago

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.

felangel commented 9 months ago

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