-
Notifications
You must be signed in to change notification settings - Fork 41
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
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f7f31e3
fix w/out tests (only manual tests are done)
kushti 5063bae
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti 166c261
merging w. 6.0.0
kushti edc91ba
tests
kushti d8fab5e
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti 29ed83a
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti 5cabedd
equalsPairCollWithCollOverArray
kushti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,7 +139,13 @@ class CollOverArray[@specialized A](val toArray: Array[A], val builder: CollBuil | |
|
||
override def equals(obj: scala.Any): Boolean = (this eq obj.asInstanceOf[AnyRef]) || (obj match { | ||
case obj: CollOverArray[_] if obj.tItem == this.tItem => | ||
java.util.Objects.deepEquals(obj.toArray, toArray) | ||
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) | ||
} else { | ||
false | ||
} | ||
case _ => false | ||
}) | ||
|
||
|
@@ -241,8 +247,15 @@ private[sigma] class CollOverArrayBuilder extends CollBuilder { builder => | |
|
||
class PairOfCols[@specialized L, @specialized R](val ls: Coll[L], val rs: Coll[R]) extends PairColl[L,R] { | ||
|
||
override def equals(that: scala.Any) = (this eq that.asInstanceOf[AnyRef]) || (that match { | ||
case that: PairColl[_,_] if that.tItem == this.tItem => ls == that.ls && rs == that.rs | ||
override def equals(that: scala.Any): Boolean = (this eq that.asInstanceOf[AnyRef]) || (that match { | ||
case that: PairColl[_,_] if that.tItem == this.tItem => | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} else { | ||
false | ||
} | ||
case _ => false | ||
}) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 inequals
. Here it can be done by accessingobj.ls
,obj.rs
and comparing with this.toArray in a cfor loop.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, please check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.