Skip to content
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

Bitwise operations #131

Merged
merged 2 commits into from Oct 19, 2022
Merged

Bitwise operations #131

merged 2 commits into from Oct 19, 2022

Conversation

Ladicek
Copy link
Contributor

@Ladicek Ladicek commented Oct 18, 2022

No description provided.

…ated `equals()`

The `Gizmo.generateEquals()` method used to emit direct `==` comparison
even for `float` and `double` fields. This is inconsistent with how
arrays of these types are compared (`Arrays.equals()`) and also with
the template code IntelliJ generates.

This commit changes that to bitwise comparison. Specifically, `float`
comparison is now an `int` comparison of `Float.floatToIntBits`, and
`double` comparison is `long` comparison of `Double.doubleToLongBits`.
@Ladicek
Copy link
Contributor Author

Ladicek commented Oct 18, 2022

I need bitwise XOR to implement Annotation.hashCode(), and I thought I'd add AND and OR too.

The 2nd commit slightly adjusts the generated equals() method when it comes to float and double fields, because I noticed simple == is inconsistent with what Arrays.equals() do and also with what IntelliJ generates from its template. I don't insist hard on this, it just feels better. (Would be good to know what Eclipse generates, too :-) )

Comment on lines +1116 to +1117
// this is consistent with Arrays.equals() and it's also what IntelliJ generates
equals.ifIntegerEqual(equals.invokeStaticMethod(FLOAT_TO_INT_BITS, thisValue), equals.invokeStaticMethod(FLOAT_TO_INT_BITS, thatValue))
Copy link
Member

@dmlloyd dmlloyd Oct 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's pretty wild that Arrays.equals() is doing this kind of semi-bitwise equality. 🤯

Importantly, this also makes this method consistent with Float.hashCode() which is doing floatToIntBits as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, I didn't even notice what Float|Double.hashCode() does, good point.

@Ladicek Ladicek merged commit 9c1c4b3 into quarkusio:main Oct 19, 2022
@Ladicek Ladicek deleted the bitwise-operations branch October 19, 2022 07:13
@gsmet
Copy link
Member

gsmet commented Oct 19, 2022

@Ladicek do you have anything else planned or should I ship a release?

@Ladicek
Copy link
Contributor Author

Ladicek commented Oct 19, 2022

@gsmet if you could do a release now, that would be great! I have a few changes for Quarkus waiting for my recent Gizmo improvements.

I do have some more improvements in mind, but those don't block any immediate Quarkus work and are longer term anyway.

@gsmet
Copy link
Member

gsmet commented Oct 19, 2022

1.4.0.Final should be available in Maven Central in ~30 minutes.

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

Successfully merging this pull request may close these issues.

None yet

4 participants