@@ -1042,18 +1042,23 @@ namespace ts {
1042
1042
let _jsxNamespace: __String;
1043
1043
let _jsxFactoryEntity: EntityName | undefined;
1044
1044
1045
- class InfiniMap <K, V> {
1046
- private next?: InfiniMap <K, V>;
1045
+ class ExpandableRelationshipCache <K, V> {
1046
+ private next?: ExpandableRelationshipCache <K, V>;
1047
1047
private inner: ESMap<K, V>;
1048
1048
constructor() {
1049
1049
this.inner = new Map();
1050
1050
}
1051
1051
get(key: K): V | undefined {
1052
1052
return this.inner.has(key) ? this.inner.get(key) : this.next?.get(key);
1053
1053
}
1054
+ /**
1055
+ * Unlike a normal map, this expects `set` to be called exactly once for a given key, and then never again
1056
+ * - the caller should always be checking if the cache `.has` the member it would set.
1057
+ */
1054
1058
set(key: K, value: V): this {
1059
+ Debug.assert(!this.inner.has(key));
1055
1060
if (this.inner.size > ((2 ** 24) - 1)) {
1056
- this.next ||= new InfiniMap ();
1061
+ this.next ||= new ExpandableRelationshipCache ();
1057
1062
this.next.set(key, value);
1058
1063
}
1059
1064
else {
@@ -1072,7 +1077,7 @@ namespace ts {
1072
1077
delete(key: K): boolean {
1073
1078
return this.inner.delete(key) || !!this.next?.delete(key);
1074
1079
}
1075
- forEach(callbackfn: (value: V, key: K, map: InfiniMap <K, V>) => void): void {
1080
+ forEach(callbackfn: (value: V, key: K, map: ExpandableRelationshipCache <K, V>) => void): void {
1076
1081
this.inner.forEach((v, k) => callbackfn(v, k, this));
1077
1082
this.next?.forEach((v, k) => callbackfn(v, k, this));
1078
1083
}
@@ -1081,13 +1086,13 @@ namespace ts {
1081
1086
}
1082
1087
}
1083
1088
1084
- type RelationCache = InfiniMap <string, RelationComparisonResult>;
1085
- const subtypeRelation = new InfiniMap <string, RelationComparisonResult>();
1086
- const strictSubtypeRelation = new InfiniMap <string, RelationComparisonResult>();
1087
- const assignableRelation = new InfiniMap <string, RelationComparisonResult>();
1088
- const comparableRelation = new InfiniMap <string, RelationComparisonResult>();
1089
- const identityRelation = new InfiniMap <string, RelationComparisonResult>();
1090
- const enumRelation = new InfiniMap <string, RelationComparisonResult>();
1089
+ type RelationCache = ExpandableRelationshipCache <string, RelationComparisonResult>;
1090
+ const subtypeRelation = new ExpandableRelationshipCache <string, RelationComparisonResult>();
1091
+ const strictSubtypeRelation = new ExpandableRelationshipCache <string, RelationComparisonResult>();
1092
+ const assignableRelation = new ExpandableRelationshipCache <string, RelationComparisonResult>();
1093
+ const comparableRelation = new ExpandableRelationshipCache <string, RelationComparisonResult>();
1094
+ const identityRelation = new ExpandableRelationshipCache <string, RelationComparisonResult>();
1095
+ const enumRelation = new ExpandableRelationshipCache <string, RelationComparisonResult>();
1091
1096
1092
1097
const builtinGlobals = createSymbolTable();
1093
1098
builtinGlobals.set(undefinedSymbol.escapedName, undefinedSymbol);
0 commit comments