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

[6.0] Improve collections equality #1011

Merged
merged 7 commits into from
Oct 18, 2024
Merged

[6.0] Improve collections equality #1011

merged 7 commits into from
Oct 18, 2024

Conversation

kushti
Copy link
Member

@kushti kushti commented Jun 13, 2024

In this PR, PairOfColl made equal with CollOverArray (when contents is the same), starting from 6.0 version of the protocol

close #909

@kushti kushti changed the base branch from develop to v6.0.0 June 13, 2024 10:07
@kushti kushti self-assigned this Jun 13, 2024
@kushti kushti added this to the v6.0 milestone Jun 13, 2024
Copy link
Member

@aslesarenko aslesarenko left a comment

Choose a reason for hiding this comment

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

LGTM, but please address the comments

java.util.Objects.deepEquals(obj.toArray, this.toArray)
case obj: PairColl[_, _] if obj.tItem == this.tItem =>
if(VersionContext.current.isV6SoftForkActivated) {
java.util.Objects.deepEquals(obj.toArray, this.toArray)
Copy link
Member

Choose a reason for hiding this comment

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

the obj.toArray will lead to many allocations (one for the array, and one for each pair). It is better to avoid it allocations in equals. Here it can be done by accessing obj.ls, obj.rs and comparing with this.toArray in a cfor loop.

Copy link
Member Author

Choose a reason for hiding this comment

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

done, please check

Copy link
Member

Choose a reason for hiding this comment

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

Looks good.

ls == that.ls && rs == that.rs
case that: CollOverArray[_] if that.tItem == this.tItem =>
if (VersionContext.current.isV6SoftForkActivated) {
java.util.Objects.deepEquals(that.toArray, this.toArray)
Copy link
Member

Choose a reason for hiding this comment

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

The comparison loop above (once implemented) can be reused here to avoid allocations.

@kushti kushti merged commit 571e721 into v6.0.0 Oct 18, 2024
4 checks passed
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