Changing type mapping cache to be a dictionary

This commit is contained in:
Anders Hejlsberg
2015-05-21 09:18:55 -07:00
parent c303e14b28
commit ebcdd85ad0
2 changed files with 6 additions and 12 deletions
+5 -6
View File
@@ -3869,14 +3869,13 @@ module ts {
// If this type has already been instantiated using this mapper, returned the cached result. This guards against
// infinite instantiations of cyclic types, e.g. "var x: { a: T, b: typeof x };"
if (mapper.mappings) {
for (let mapping of mapper.mappings) {
if (mapping.type === type) {
return mapping.result;
}
let cached = <ObjectType>mapper.mappings[type.id];
if (cached) {
return cached;
}
}
else {
mapper.mappings = [];
mapper.mappings = {};
}
// Instantiate the given type using the given mapper and cache the result
let result = <ResolvedType>createObjectType(TypeFlags.Anonymous, type.symbol);
@@ -3888,7 +3887,7 @@ module ts {
let numberIndexType = getIndexTypeOfType(type, IndexKind.Number);
if (stringIndexType) result.stringIndexType = instantiateType(stringIndexType, mapper);
if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper);
mapper.mappings.push({ type, result });
mapper.mappings[type.id] = result;
return result;
}
+1 -6
View File
@@ -1586,15 +1586,10 @@ module ts {
Number,
}
export interface TypeMapping {
type: Type;
result: Type;
}
/* @internal */
export interface TypeMapper {
(t: TypeParameter): Type;
mappings?: TypeMapping[]; // Type mapping cache
mappings?: Map<Type>; // Type mapping cache
}
/* @internal */