-
Notifications
You must be signed in to change notification settings - Fork 57
Changes to the FormulaManager.equal and FormulaManager.distinct API #584
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
base: master
Are you sure you want to change the base?
Conversation
baierd
left a comment
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.
LGTM
| default BooleanFormula equal(Formula... pArgs) { | ||
| return equal(ImmutableList.copyOf(pArgs)); | ||
| default BooleanFormula makeEqual(Formula... pArgs) { | ||
| return makeEqual(FluentIterable.from(pArgs)); |
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.
I would simply use Arrays.asList here. FluentIterable has no benefit, and just creates one more object for wrapping the array.
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
| public BooleanFormula makeEqual(Iterable<Formula> pArgs) { | ||
| final Collection<Formula> args = ImmutableList.copyOf(pArgs); | ||
| if (args.size() < 2) { |
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.
This change doesn't make sense. If you really need a size, it is better to require Collection. Right now you force an unnecessary eager copy on every caller, even if they already have a Collection (as long as it does not happen to be an ImmutableCollection). If you would require Collection, only callers that do not have one need to copy.
I was thinking that you do not need the size and can accept Iterable at no cost. Checking whether the input is empty or has one element does not need the size. And it could anyway be done after the copy that is already made later on in the method.
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.
It's possible to remove the check entirely, see 7009c86. However, we then have to handle the special case for each solver separately
Should I keep it this way, or revert to Collection for the argument type?
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.
That is up to the maintainers to decide. It just wanted to say that it does not make sense to force an eager copy of an Iterable if using Collection would get rid of the copy, in particular given that there was yet another eager copy made.
Either requiring a Collection with no eager copy, or allowing Iterable with just one eager copy, or allowing Iterable with no eager copy (and decentralized length checks) might be meaningful options. And there is also the alternative to check whether the Iterable has more than one element by using the iterator manually.
As suggested by @PhilippWendler:
Iterablesas arguments forFormulaManager.equalandFormulaManager.distinctmakeEqualandmakeDistinctFluentIterableto avoid unnecessary copyingSee #559 for the discussion