Skip to content

hashCode for double: difference dart/js #35116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
frankpepermans opened this issue Nov 9, 2018 · 3 comments
Closed

hashCode for double: difference dart/js #35116

frankpepermans opened this issue Nov 9, 2018 · 3 comments

Comments

@frankpepermans
Copy link

If I run the following code in dart2js or in dartdevc
print((10.4).hashCode);
print((10.8).hashCode);

I get 10 in both cases, seems related to #2884

@matanlurey matanlurey added web-dart2js needs-info We need additional information from the issue author (auto-closed after 14 days if no response) web-dev-compiler labels Nov 11, 2018
@matanlurey
Copy link
Contributor

This might be due to performance considerations for Dart2JS/DDC, since JavaScript doesn't have differentiation between int and double (all JavaScript numbers are floating point values).

/cc @rakudrama @jmesserly

@jmesserly jmesserly removed the needs-info We need additional information from the issue author (auto-closed after 14 days if no response) label Nov 14, 2018
@jmesserly
Copy link

jmesserly commented Nov 14, 2018

Good find on #2884! This seems to have been fixed for the VM but not other implementations: 1db8615

We could mix some of the non-integral parts of the JS Number into the hashCode.

@rakudrama
Copy link
Member

Fixed via ea6d343

There is one 'num' method for both int and double.

The method is now bigger so no longer gets inlined, so is a little slower for integers.
get:hashCode usually didn't get inlined anyway (e.g. in HashMap implementations it is an interface call).
It is quite a bit slower for non-integers, but presumably this is (1) not very common and (2) there is a benefit from avoiding hash table collisions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants