mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Merge pull request #10240 from Microsoft/optimizeTypeListIds
Optimize format of type list id strings used in maps
This commit is contained in:
@@ -4948,24 +4948,27 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getTypeListId(types: Type[]) {
|
||||
let result = "";
|
||||
if (types) {
|
||||
switch (types.length) {
|
||||
case 1:
|
||||
return "" + types[0].id;
|
||||
case 2:
|
||||
return types[0].id + "," + types[1].id;
|
||||
default:
|
||||
let result = "";
|
||||
for (let i = 0; i < types.length; i++) {
|
||||
if (i > 0) {
|
||||
result += ",";
|
||||
}
|
||||
result += types[i].id;
|
||||
}
|
||||
return result;
|
||||
const length = types.length;
|
||||
let i = 0;
|
||||
while (i < length) {
|
||||
const startId = types[i].id;
|
||||
let count = 1;
|
||||
while (i + count < length && types[i + count].id === startId + count) {
|
||||
count++;
|
||||
}
|
||||
if (result.length) {
|
||||
result += ",";
|
||||
}
|
||||
result += startId;
|
||||
if (count > 1) {
|
||||
result += ":" + count;
|
||||
}
|
||||
i += count;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
return result;
|
||||
}
|
||||
|
||||
// This function is used to propagate certain flags when creating new object type references and union types.
|
||||
|
||||
Reference in New Issue
Block a user