Simplify the syntax in `UnionType.Builder::addAlternate`.
This is a no-op change.
@@ -844,10 +844,14 @@ public class UnionType extends JSType {
if (isAlternateUnknown) {
areAllUnknownsChecked = areAllUnknownsChecked && alternate.isCheckedUnknownType();
}
- if (!isAllType && !isNativeUnknownType) {
+
+ if (isAllType || isNativeUnknownType) {
+ return this;
+ }
if (alternate.isUnionType()) {
addAlternates(alternate.toMaybeUnionType().getAlternates());
- } else {
+ return this;
+ }
if (alternates.size() > maxUnionSize) {
return this;
}
@@ -866,11 +870,9 @@ public class UnionType extends JSType {
// Look through the alternates we've got so far,
// and check if any of them are duplicates of
// one another.
- int currentIndex = 0;
- Iterator<JSType> it = alternates.iterator();
- while (it.hasNext()) {
+ for (int index = 0; index < alternates.size(); index++) {
boolean removeCurrent = false;
- JSType current = it.next();
+ JSType current = alternates.get(index);
// Unknown and NoResolved types may just be names that haven't
// been resolved yet. So keep these in the union, and just use
@@ -885,8 +887,7 @@ public class UnionType extends JSType {
// Alternate is unnecessary.
return this;
}
- } else {
-
+ } else if (alternate.isTemplatizedType() || current.isTemplatizedType()) {
// Because "Foo" and "Foo<?>" are roughly equivalent
// templatized types, special care is needed when building the
// union. For example:
@@ -895,7 +896,6 @@ public class UnionType extends JSType {
// building the subtype.
//
- if (alternate.isTemplatizedType() || current.isTemplatizedType()) {
// Cases:
// 1) alternate:Array<string> and current:Object ==> Object
// 2) alternate:Array<string> and current:Array ==> Array
@@ -958,19 +958,18 @@ public class UnionType extends JSType {
mayRegisterDroppedProperties(current, alternate);
removeCurrent = true;
}
- }
if (removeCurrent) {
- it.remove();
+ alternates.remove(index);
- if (currentIndex == functionTypePosition) {
+ if (index == functionTypePosition) {
functionTypePosition = -1;
- } else if (currentIndex < functionTypePosition) {
+ } else if (index < functionTypePosition) {
functionTypePosition--;
- currentIndex--;
}
+
+ index--;
}
- currentIndex++;
}
if (alternate.isFunctionType()) {
@@ -980,8 +979,6 @@ public class UnionType extends JSType {
}
alternates.add(alternate);
- }
- }
return this;
}
