8000 Changing type mapping cache to be a dictionary · myrtleTree33/TypeScript@ebcdd85 · GitHub
[go: up one dir, main page]

Skip to content

Commit ebcdd85

Browse files
committed
Changing type mapping cache to be a dictionary
1 parent c303e14 commit ebcdd85

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3869,14 +3869,13 @@ module ts {
38693869
// If this type has already been instantiated using this mapper, returned the cached result. This guards against
38703870
// infinite instantiations of cyclic types, e.g. "var x: { a: T, b: typeof x };"
38713871
if (mapper.mappings) {
3872-
for (let mapping of mapper.mappings) {
3873-
if (mapping.type === type) {
3874-
return mapping.result;
3875-
}
3872+
let cached = <ObjectType>mapper.mappings[type.id];
3873+
if (cached) {
3874+
return cached;
38763875
}
38773876
}
38783877
else {
3879-
mapper.mappings = [];
3878+
mapper.mappings = {};
38803879
}
38813880
// Instantiate the given type using the given mapper and cache the result
38823881
let result = <ResolvedType>createObjectType(TypeFlags.Anonymous, type.symbol);
@@ -3888,7 +3887,7 @@ module ts {
38883887
let numberIndexType = getIndexTypeOfType(type, IndexKind.Number);
38893888
if (stringIndexType) result.stringIndexType = instantiateType(stringIndexType, mapper);
38903889
if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper);
3891-
mapper.mappings.push({ type, result });
3890+
mapper.mappings[type.id] = result;
38923891
return result;
38933892
}
38943893

src/compiler/types.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,15 +1586,10 @@ module ts {
15861586
Number,
15871587
}
15881588

1589-
export interface TypeMapping {
1590-
type: Type;
1591-
result: Type;
1592-
}
1593-
15941589
/* @internal */
15951590
export interface TypeMapper {
15961591
(t: TypeParameter): Type;
1597-
mappings?: TypeMapping[]; // Type mapping cache
1592+
mappings?: Map<Type>; // Type mapping cache
15981593
}
15991594

16001595
/* @internal */

0 commit comments

Comments
 (0)
0