Skip to content

Commit e00ce94

Browse files
authored
Merge pull request #10240 from Microsoft/optimizeTypeListIds
Optimize format of type list id strings used in maps
2 parents e900952 + 9d4547c commit e00ce94

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
@@ -4948,24 +4948,27 @@ namespace ts {
4948
}
4948
}
4949

4949

4950
function getTypeListId(types: Type[]) {
4950
function getTypeListId(types: Type[]) {
4951+
let result = "";
4951
if (types) {
4952
if (types) {
4952-
switch (types.length) {
4953+
const length = types.length;
4953-
case 1:
4954+
let i = 0;
4954-
return "" + types[0].id;
4955+
while (i < length) {
4955-
case 2:
4956+
const startId = types[i].id;
4956-
return types[0].id + "," + types[1].id;
4957+
let count = 1;
4957-
default:
4958+
while (i + count < length && types[i + count].id === startId + count) {
4958-
let result = "";
4959+
count++;
4959-
for (let i = 0; i < types.length; i++) {
4960+
}
4960-
if (i > 0) {
4961+
if (result.length) {
4961-
result += ",";
4962+
result += ",";
4962-
}
4963+
}
4963-
result += types[i].id;
4964+
result += startId;
4964-
}
4965+
if (count > 1) {
4965-
return result;
4966+
result += ":" + count;
4967+
}
4968+
i += count;
4966
}
4969
}
4967
}
4970
}
4968-
return "";
4971+
return result;
4969
}
4972
}
4970

4973

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

0 commit comments

Comments
 (0)