Skip to content

Commit 577f4cb

Browse files
lauraharkercopybara-github
authored andcommitted
Remove unnecessary isSubtypeOf check in InvocationTemplateTypeMatcher
I suspect the intent of the isSubtypeOf check was to mainly save time and avoid unnecessary matchTemplateTypesRecursive calls. In practice, it seems cheaper to just do the recursive call. Subtype checks are especially costly for structural types, where we recursively call isSubtypeOf on each property. PiperOrigin-RevId: 515401346
1 parent 9cc595c commit 577f4cb

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/com/google/javascript/jscomp/InvocationTemplateTypeMatcher.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,16 @@ private void matchTemplateTypesRecursive(JSType paramType, JSType argType) {
187187
return;
188188
}
189189

190-
ObjectType referencedParamType = templatizedParamType.getReferencedType();
191190
JSType argObjectType = argType.restrictByNotNullOrUndefined().collapseUnion();
191+
// Resolve any template types in common between the argument type and parameter type
192+
TemplateTypeMap paramTypeMap = paramType.getTemplateTypeMap();
192193

193-
if (argObjectType.isSubtypeOf(referencedParamType)) {
194-
// If the argument type is a subtype of the parameter type, resolve any
195-
// template types amongst their templatized types.
196-
TemplateTypeMap paramTypeMap = paramType.getTemplateTypeMap();
197-
198-
ImmutableList<TemplateType> keys = paramTypeMap.getTemplateKeys();
199-
TemplateTypeMap argTypeMap = argObjectType.getTemplateTypeMap();
200-
for (int index = keys.size() - keyCount; index < keys.size(); index++) {
201-
TemplateType key = keys.get(index);
202-
this.matchTemplateTypesRecursive(
203-
paramTypeMap.getResolvedTemplateType(key), argTypeMap.getResolvedTemplateType(key));
204-
}
194+
ImmutableList<TemplateType> keys = paramTypeMap.getTemplateKeys();
195+
TemplateTypeMap argTypeMap = argObjectType.getTemplateTypeMap();
196+
for (int index = keys.size() - keyCount; index < keys.size(); index++) {
197+
TemplateType key = keys.get(index);
198+
this.matchTemplateTypesRecursive(
199+
paramTypeMap.getResolvedTemplateType(key), argTypeMap.getResolvedTemplateType(key));
205200
}
206201
}
207202
}

0 commit comments

Comments
 (0)