mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-17 01:49:41 -05:00
Shared caching for identical function types in relationship checking
This commit is contained in:
@@ -16092,6 +16092,21 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
function isSimpleFunctionType(type: Type) {
|
||||
const signature = getSingleCallSignature(type);
|
||||
return signature && signature.parameters.length <= 2 && !signature.thisParameter &&
|
||||
!signature.hasRestParameter && !getTypePredicateOfSignature(signature);
|
||||
}
|
||||
|
||||
function getFunctionTypeId(type: ResolvedType): string {
|
||||
const signature = type.callSignatures[0];
|
||||
let result = "" + signature.minArgumentCount;
|
||||
for (const p of signature.parameters) {
|
||||
result += "@" + getTypeOfSymbol(p).id + p.escapedName;
|
||||
}
|
||||
return result + ":" + getReturnTypeOfSignature(signature).id;
|
||||
}
|
||||
|
||||
/**
|
||||
* To improve caching, the relation key for two generic types uses the target's id plus ids of the type parameters.
|
||||
* For other cases, the types ids are used.
|
||||
@@ -16106,6 +16121,9 @@ namespace ts {
|
||||
const typeParameters: Type[] = [];
|
||||
return getTypeReferenceId(<TypeReference>source, typeParameters) + "," + getTypeReferenceId(<TypeReference>target, typeParameters);
|
||||
}
|
||||
if (isSimpleFunctionType(source) && isSimpleFunctionType(target)) {
|
||||
return getFunctionTypeId(<ResolvedType>source) + "," + getFunctionTypeId(<ResolvedType>target);
|
||||
}
|
||||
return source.id + "," + target.id;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user