Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Consider optimizing .equals() operations #455

Open
CeylonMigrationBot opened this issue Mar 23, 2012 · 8 comments
Open

Consider optimizing .equals() operations #455

CeylonMigrationBot opened this issue Mar 23, 2012 · 8 comments

Comments

@CeylonMigrationBot
Copy link

[@emmanuelbernard] One use case for identity comparison in Java is to optimize .equals() implementations. If two instances are identical identity wise, they must be equal.

The compiler could enforce that automatically so that this use case for Ceylon's === is no longer needed.

Ceylon a == b would become in Java (a==b) || a.equals(b)

[Migrated from ceylon/ceylon-compiler#455]

@CeylonMigrationBot
Copy link
Author

[@quintesse] Just to document a couple of remarks from the Skype discussion:

  1. The spec would have to change to indicate this. Because it would become impossible to write an equals function that always returns false for example.
  2. Passing equals() as a method reference or as a higher order function would suddenly use a slower code-path

@CeylonMigrationBot
Copy link
Author

[@emmanuelbernard] Not sure why 2. would be the case. the optimization would be an implementation of equals(), no?

@CeylonMigrationBot
Copy link
Author

[@quintesse] Well that's because this:

Ceylon `a == b` would become in Java `(a==b) || a.equals(b)`

suggests that it's the test that changes, not the implementation of equals, although I guess that could be done as well, Wrapping the code inside the equals in an if (a== b) { return true; } else { /* wrapped code here */ }

@CeylonMigrationBot
Copy link
Author

[@FroMage] If we put that optimisation as inserted code at the beginning of each equals() method we don't have to use a let on every call-site and method references to equals will still be optimised.

@CeylonMigrationBot
Copy link
Author

[@FroMage] Will wait for M4.

@CeylonMigrationBot
Copy link
Author

[@FroMage] Optims for M5.

@CeylonMigrationBot
Copy link
Author

[@FroMage] Moving to M6

@CeylonMigrationBot
Copy link
Author

[@FroMage] Moving to 1.2

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

No branches or pull requests

1 participant