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

fix: Minor QoL clean up #175

Merged
merged 4 commits into from
Dec 18, 2024
Merged

fix: Minor QoL clean up #175

merged 4 commits into from
Dec 18, 2024

Conversation

bryanhuhta
Copy link
Contributor

@bryanhuhta bryanhuhta commented Dec 16, 2024

This PR performs some housekeeping tasks like removing unused imports and removing unused return values.

Also reflects the equals() change to hashCode() and adds tests for both
implementations.
@bryanhuhta bryanhuhta self-assigned this Dec 16, 2024
@bryanhuhta bryanhuhta requested review from a team as code owners December 16, 2024 21:51
Comment on lines 20 to 29

Ref<?> valueRef = (Ref<?>) o;
if (val.getClass() != o.getClass()) return false;

return id.equals(valueRef.id) && val.equals(valueRef.val);
}

@Override
public int hashCode() {
return id.hashCode();
return Objects.hash(id, val);
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure we want this change. The value here can be a string or a container type (we seem to be using maps as T), and if it is a container type we'll end up doing a deep traversal for equals() and hashCode() as opposed to a simple integer comparison / hashing which can become bad for performance.

Semantically, ids should be unique and generated based on a similar (and somewhat expensive) map lookup, so we should be fine with using the id only.

@korniltsev can you confirm this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In 32f2f77 I reverted this change. I did this in the interest of keeping the changes in this PR non-controversial. I mostly wanted this PR to clean up a few untidy spots in the code base.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@korniltsev can you confirm this?

I confirm the id already represents the contents of the value which is uniquely stored in a mp Aleks pointed. It will not hurt to hash/equals the value, but it is also not needed.

@bryanhuhta bryanhuhta enabled auto-merge December 17, 2024 23:42
@@ -16,7 +16,8 @@ public Ref(T val, Long id) {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Ref<T> valueRef = (Ref<T>) o;

Ref<?> valueRef = (Ref<?>) o;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note this uses ? instead of T. I gather that ? is somewhat safer when casting generic classes.

Copy link
Collaborator

@korniltsev korniltsev left a comment

Choose a reason for hiding this comment

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

lgtm, thanks

@bryanhuhta bryanhuhta merged commit d7469e9 into main Dec 18, 2024
40 checks passed
@bryanhuhta bryanhuhta deleted the cleanup branch December 18, 2024 05:12
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.

3 participants