Skip to content

Commit 9d4547c

Browse files
committed
Optimize format of type list id strings used in maps
1 parent 3f1ec7a commit 9d4547c

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/compiler/checker.ts

Lines changed: 18 additions & 15 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -4941,24 +4941,27 @@ namespace ts {
4941
}
4941
}
4942

4942

4943
function getTypeListId(types: Type[]) {
4943
function getTypeListId(types: Type[]) {
4944+
let result = "";
4944
if (types) {
4945
if (types) {
4945-
switch (types.length) {
4946+
const length = types.length;
4946-
case 1:
4947+
let i = 0;
4947-
return "" + types[0].id;
4948+
while (i < length) {
4948-
case 2:
4949+
const startId = types[i].id;
4949-
return types[0].id + "," + types[1].id;
4950+
let count = 1;
4950-
default:
4951+
while (i + count < length && types[i + count].id === startId + count) {
4951-
let result = "";
4952+
count++;
4952-
for (let i = 0; i < types.length; i++) {
4953+
}
4953-
if (i > 0) {
4954+
if (result.length) {
4954-
result += ",";
4955+
result += ",";
4955-
}
4956+
}
4956-
result += types[i].id;
4957+
result += startId;
4957-
}
4958+
if (count > 1) {
4958-
return result;
4959+
result += ":" + count;
4960+
}
4961+
i += count;
4959
}
4962
}
4960
}
4963
}
4961-
return "";
4964+
return result;
4962
}
4965
}
4963

4966

4964
// This function is used to propagate certain flags when creating new object type references and union types.
4967
// This function is used to propagate certain flags when creating new object type references and union types.

0 commit comments

Comments
 (0)