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

Simplify KeyAndType equals / hashCode #705

Merged
merged 1 commit into from
Feb 26, 2024
Merged

Simplify KeyAndType equals / hashCode #705

merged 1 commit into from
Feb 26, 2024

Conversation

kilink
Copy link
Member

@kilink kilink commented Feb 25, 2024

Simplify equals / hashCode for KeyAndType, add toString implementation for debugging. Additionally, avoid Optional / lambda allocation in some places.

Simplify equals / hashCode for KeyAndType, add toString implementation for debugging.
Additionally, avoid Optional / lambda allocation in some places.
result = prime * result + ((key == null) ? 0 : key.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = 31 * result + Objects.hashCode(key);
result = 31 * result + Objects.hashCode(type);
return result;
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't we just return Objects.hash(key, type)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't use it because it's a vararg method, so allocates an array. Maybe it doesn't matter here, or would get inlined by the JIT anyway, I don't know.

@kilink kilink merged commit 483949d into 2.x Feb 26, 2024
10 checks passed
@kilink kilink deleted the key-and-type-2 branch February 26, 2024 17:56
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.

2 participants