@@ -8735,11 +8735,12 @@ namespace ts {
87358735 containingMessageChain?: DiagnosticMessageChain): boolean {
87368736
87378737 let errorInfo: DiagnosticMessageChain;
8738+ let maybeKeys: string[];
87388739 let sourceStack: Type[];
87398740 let targetStack: Type[];
8740- let maybeStack: Map<RelationComparisonResult>[];
8741- let expandingFlags: number;
8741+ let maybeCount = 0;
87428742 let depth = 0;
8743+ let expandingFlags = 0;
87438744 let overflow = false;
87448745 let isIntersectionConstituent = false;
87458746
@@ -9107,10 +9108,15 @@ namespace ts {
91079108 return related === RelationComparisonResult.Succeeded ? Ternary.True : Ternary.False;
91089109 }
91099110 }
9110- if (depth > 0) {
9111- for (let i = 0; i < depth; i++) {
9111+ if (!maybeKeys) {
9112+ maybeKeys = [];
9113+ sourceStack = [];
9114+ targetStack = [];
9115+ }
9116+ else {
9117+ for (let i = 0; i < maybeCount; i++) {
91129118 // If source and target are already being compared, consider them related with assumptions
9113- if (maybeStack [i].get(id) ) {
9119+ if (id === maybeKeys [i]) {
91149120 return Ternary.Maybe;
91159121 }
91169122 }
@@ -9119,16 +9125,11 @@ namespace ts {
91199125 return Ternary.False;
91209126 }
91219127 }
9122- else {
9123- sourceStack = [];
9124- targetStack = [];
9125- maybeStack = [];
9126- expandingFlags = 0;
9127- }
9128+ const maybeStart = maybeCount;
9129+ maybeKeys[maybeCount] = id;
9130+ maybeCount++;
91289131 sourceStack[depth] = source;
91299132 targetStack[depth] = target;
9130- maybeStack[depth] = createMap<RelationComparisonResult>();
9131- maybeStack[depth].set(id, RelationComparisonResult.Succeeded);
91329133 depth++;
91339134 const saveExpandingFlags = expandingFlags;
91349135 if (!(expandingFlags & 1) && isDeeplyNestedType(source, sourceStack, depth)) expandingFlags |= 1;
@@ -9137,15 +9138,19 @@ namespace ts {
91379138 expandingFlags = saveExpandingFlags;
91389139 depth--;
91399140 if (result) {
9140- const maybeCache = maybeStack[depth];
9141- // If result is definitely true, copy assumptions to global cache, else copy to next level up
9142- const destinationCache = (result === Ternary.True || depth === 0) ? relation : maybeStack[depth - 1];
9143- copyEntries(maybeCache, destinationCache);
9141+ if (result === Ternary.True || depth === 0) {
9142+ // If result is definitely true, record all maybe keys as having succeeded
9143+ for (let i = maybeStart; i < maybeCount; i++) {
9144+ relation.set(maybeKeys[i], RelationComparisonResult.Succeeded);
9145+ }
9146+ maybeCount = maybeStart;
9147+ }
91449148 }
91459149 else {
9146- // A false result goes straight into global cache (when something is false under assumptions it
9147- // will also be false without assumptions)
9150+ // A false result goes straight into global cache (when something is false under
9151+ // assumptions it will also be false without assumptions)
91489152 relation.set(id, reportErrors ? RelationComparisonResult.FailedAndReported : RelationComparisonResult.Failed);
9153+ maybeCount = maybeStart;
91499154 }
91509155 return result;
91519156 }
0 commit comments