Store results of `hasMultiple` in local variables to avoid duplicate computation.
RELNOTES=n/a
@@ -662,13 +662,15 @@ public class IterableSubject extends Subject {
private static ElementFactGrouping pickGrouping(
Iterable<Entry<?>> first, Iterable<Entry<?>> second) {
- if (anyHasMultiple(first, second) && anyContainsCommaOrNewline(first, second)) {
+ boolean firstHasMultiple = hasMultiple(first);
+ boolean secondHasMultiple = hasMultiple(second);
+ if ((firstHasMultiple || secondHasMultiple) && anyContainsCommaOrNewline(first, second)) {
return FACT_PER_ELEMENT;
}
- if (hasMultiple(first) && containsEmptyOrLong(first)) {
+ if (firstHasMultiple && containsEmptyOrLong(first)) {
return FACT_PER_ELEMENT;
}
- if (hasMultiple(second) && containsEmptyOrLong(second)) {
+ if (secondHasMultiple && containsEmptyOrLong(second)) {
return FACT_PER_ELEMENT;
}
return ALL_IN_ONE_FACT;
@@ -684,15 +686,6 @@ public class IterableSubject extends Subject {
return false;
}
- private static boolean anyHasMultiple(Iterable<Entry<?>>... lists) {
- for (Iterable<Entry<?>> list : lists) {
- if (hasMultiple(list)) {
- return true;
- }
- }
- return false;
- }
-
private static boolean hasMultiple(Iterable<Entry<?>> entries) {
int totalCount = 0;
for (Multiset.Entry<?> entry : entries) {
