Skip to content

Commit

Permalink
Automated g4 rollback of changelist 139602401.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

breaks jdossier because it introduces a binary incompatibility and jdossier is built against one version of rhino and runs against head... which is sad and should be fixed

*** Original change description ***

Change UnionType to hold a List instead of a Collection for the alternates and switch most accessors to do indexed iteration.

heap profiling showed that the iteration in JsType.checkEquivalenceHelper was allocating lots of iterators. This is an easy, if slightly annoying, way to make these operations a little cheaper.

***

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=139623208
  • Loading branch information
lukesandberg authored and blickly committed Nov 19, 2016
1 parent 25a01a8 commit 7ef9044
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 107 deletions.
21 changes: 7 additions & 14 deletions src/com/google/javascript/rhino/jstype/JSType.java
Expand Up @@ -44,14 +44,13 @@
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.HashBasedTable; import com.google.common.collect.HashBasedTable;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableList;
import com.google.javascript.rhino.ErrorReporter; import com.google.javascript.rhino.ErrorReporter;
import com.google.javascript.rhino.JSDocInfo; import com.google.javascript.rhino.JSDocInfo;
import com.google.javascript.rhino.TypeI; import com.google.javascript.rhino.TypeI;
import java.io.Serializable; import java.io.Serializable;
import java.util.Comparator; import java.util.Comparator;
import java.util.IdentityHashMap; import java.util.IdentityHashMap;
import java.util.List;


/** /**
* Represents JavaScript value types.<p> * Represents JavaScript value types.<p>
Expand Down Expand Up @@ -79,8 +78,8 @@ public abstract class JSType implements TypeI, Serializable {
private static final CanCastToVisitor CAN_CAST_TO_VISITOR = private static final CanCastToVisitor CAN_CAST_TO_VISITOR =
new CanCastToVisitor(); new CanCastToVisitor();


private static final ImmutableSet<String> COVARIANT_TYPES = private static final ImmutableList<String> COVARIANT_TYPES =
ImmutableSet.of("Object", "IArrayLike", "Array"); ImmutableList.of("Object", "IArrayLike", "Array");


/** /**
* Total ordering on types based on their textual representation. * Total ordering on types based on their textual representation.
Expand Down Expand Up @@ -303,9 +302,7 @@ public boolean containsArray() {
// Check if this is a union that contains an array // Check if this is a union that contains an array
if (this.isUnionType()) { if (this.isUnionType()) {
JSType arrayType = registry.getNativeType(JSTypeNative.ARRAY_TYPE); JSType arrayType = registry.getNativeType(JSTypeNative.ARRAY_TYPE);
List<JSType> alternates = this.toMaybeUnionType().getAlternates(); for (JSType alternate : this.toMaybeUnionType().getAlternates()) {
for (int i = 0; i < alternates.size(); i++) {
JSType alternate = alternates.get(i);
if (alternate.isSubtype(arrayType)) { if (alternate.isSubtype(arrayType)) {
return true; return true;
} }
Expand Down Expand Up @@ -1129,9 +1126,7 @@ static JSType filterNoResolvedType(JSType type) {
} else if (type.isUnionType()) { } else if (type.isUnionType()) {
UnionType unionType = type.toMaybeUnionType(); UnionType unionType = type.toMaybeUnionType();
boolean needsFiltering = false; boolean needsFiltering = false;
List<JSType> alternates = unionType.getAlternates(); for (JSType alt : unionType.getAlternates()) {
for (int i = 0; i < alternates.size(); i++) {
JSType alt = alternates.get(i);
if (alt.isNoResolvedType()) { if (alt.isNoResolvedType()) {
needsFiltering = true; needsFiltering = true;
break; break;
Expand Down Expand Up @@ -1411,10 +1406,8 @@ static boolean isSubtypeHelper(JSType thisType, JSType thatType,
// unions // unions
if (thatType.isUnionType()) { if (thatType.isUnionType()) {
UnionType union = thatType.toMaybeUnionType(); UnionType union = thatType.toMaybeUnionType();
List<JSType> alternates = union.alternatesWithoutStucturalTyping; for (JSType element : union.alternatesWithoutStucturalTyping) {
// use indexed iteration to avoid iterator allocations if (thisType.isSubtype(element, implicitImplCache, subtypingMode)) {
for (int i = 0; i < alternates.size(); i++) {
if (thisType.isSubtype(alternates.get(i), implicitImplCache, subtypingMode)) {
return true; return true;
} }
} }
Expand Down

0 comments on commit 7ef9044

Please sign in to comment.