Cache substitution types (#30775)

This commit is contained in:
Wesley Wigham
2019-04-05 14:37:47 -07:00
committed by GitHub
parent 8684c3bfb8
commit c1f2aba364
2 changed files with 8 additions and 1 deletions

View File

@@ -392,6 +392,7 @@ namespace ts {
const literalTypes = createMap<LiteralType>();
const indexedAccessTypes = createMap<IndexedAccessType>();
const conditionalTypes = createMap<Type>();
const substitutionTypes = createMap<SubstitutionType>();
const evolvingArrayTypes: EvolvingArrayType[] = [];
const undefinedProperties = createMap<Symbol>() as UnderscoreEscapedMap<Symbol>;
@@ -8914,9 +8915,15 @@ namespace ts {
if (substitute.flags & TypeFlags.AnyOrUnknown) {
return typeVariable;
}
const id = `${getTypeId(typeVariable)}>${getTypeId(substitute)}`;
const cached = substitutionTypes.get(id);
if (cached) {
return cached;
}
const result = <SubstitutionType>createType(TypeFlags.Substitution);
result.typeVariable = typeVariable;
result.substitute = substitute;
substitutionTypes.set(id, result);
return result;
}