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 numberDiff line numberDiff line change
@@ -4941,24 +4941,27 @@ namespace ts {
49414941
}
49424942

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

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

0 commit comments

Comments
 (0)