Skip to content

Commit b926fcf

Browse files
committed
store exportedModulesMapLists and referencedMapLists as arrays instead of objects
1 parent b7c2161 commit b926fcf

17 files changed

+265
-266
lines changed

src/compiler/builder.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -696,23 +696,22 @@ namespace ts {
696696
fileInfos: MapLike<BuilderState.FileInfo>;
697697
options: CompilerOptions;
698698
referencedMap?: MapLike<string[] | number>;
699-
referencedMapLists?: MapLike<string[]>;
699+
referencedMapLists?: string[][];
700700
exportedModulesMap?: MapLike<string[] | number>;
701-
exportedModulesMapLists?: MapLike<string[]>;
701+
exportedModulesMapLists?: string[][];
702702
semanticDiagnosticsPerFile?: ProgramBuildInfoDiagnostic[];
703703
affectedFilesPendingEmit?: ProgramBuilderInfoFilePendingEmit[];
704704
}
705705

706706
/**
707707
* Runs deduplication on a map of references lists to reduce storage cost
708708
*/
709-
function deduplicateReferencedMap(inputMap: ReadonlyESMap<Path, BuilderState.ReferencedSet>, relativeToBuildInfo: (path: Path) => string): { map: MapLike<string[] | number>, lists?: MapLike<string[]> } {
709+
function deduplicateReferencedMap(inputMap: ReadonlyESMap<Path, BuilderState.ReferencedSet>, relativeToBuildInfo: (path: Path) => string): { map: MapLike<string[] | number>, lists?: string[][] } {
710710
const map: MapLike<string[] | number> = {};
711-
const lists: MapLike<string[]> = {};
711+
const lists: string[][] = [];
712712
const sharedMap = new Map<BuilderState.ReferencedSet, number>();
713713
const notSharedMap = new Map<BuilderState.ReferencedSet, string>();
714714
const seenSetsBySize = new Map<number, BuilderState.ReferencedSet[]>();
715-
let nextId = 0;
716715
for (const key of arrayFrom(inputMap.keys()).sort(compareStringsCaseSensitive)) {
717716
const set = inputMap.get(key)!;
718717
let sharedSet;
@@ -752,15 +751,15 @@ namespace ts {
752751
}
753752
else if(notSharedSet !== undefined) {
754753
// create a new shared list and assign both sets to it
755-
// also update the existing key with the new shared id
756-
const id = nextId++;
754+
// also update the existing key with the new shared index
755+
const idx = lists.length;
757756
const existingKey = notSharedMap.get(notSharedSet)!;
758-
sharedMap.set(set, id);
759-
sharedMap.set(notSharedSet, id);
760-
lists[id] = map[existingKey] as string[];
757+
sharedMap.set(set, idx);
758+
sharedMap.set(notSharedSet, idx);
759+
lists.push(map[existingKey] as string[]);
761760
notSharedMap.delete(notSharedSet);
762-
map[existingKey] = id;
763-
map[relativeToBuildInfo(key)] = id;
761+
map[existingKey] = idx;
762+
map[relativeToBuildInfo(key)] = idx;
764763
}
765764
else {
766765
const relativeKey = relativeToBuildInfo(key);
@@ -774,7 +773,7 @@ namespace ts {
774773
}
775774
}
776775
}
777-
return { map, lists: nextId === 0 ? undefined : lists };
776+
return { map, lists: lists.length > 0 ? lists : undefined };
778777
}
779778

780779
/**
@@ -1235,7 +1234,7 @@ namespace ts {
12351234
}
12361235
}
12371236

1238-
function getMapOfReferencedSet(mapLike: MapLike<readonly string[] | number> | undefined, lists: MapLike<readonly string[]> | undefined, toPath: (path: string) => Path): ReadonlyESMap<Path, BuilderState.ReferencedSet> | undefined {
1237+
function getMapOfReferencedSet(mapLike: MapLike<readonly string[] | number> | undefined, lists: (readonly string[])[] | undefined, toPath: (path: string) => Path): ReadonlyESMap<Path, BuilderState.ReferencedSet> | undefined {
12391238
if (!mapLike) return undefined;
12401239
const map = new Map<Path, BuilderState.ReferencedSet>();
12411240
const cache = new Map<number, BuilderState.ReferencedSet>();

tests/baselines/reference/tsbuild/demo/initial-build/in-master-branch-with-everything-setup-correctly-and-reports-no-error.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,11 @@ exports.lastElementOf = lastElementOf;
406406
],
407407
"../../zoo/zoo.ts": 0
408408
},
409-
"referencedMapLists": {
410-
"0": [
409+
"referencedMapLists": [
410+
[
411411
"../animals/index.d.ts"
412412
]
413-
},
413+
],
414414
"exportedModulesMap": {
415415
"../animals/dog.d.ts": 0,
416416
"../animals/index.d.ts": [
@@ -419,11 +419,11 @@ exports.lastElementOf = lastElementOf;
419419
],
420420
"../../zoo/zoo.ts": 0
421421
},
422-
"exportedModulesMapLists": {
423-
"0": [
422+
"exportedModulesMapLists": [
423+
[
424424
"../animals/index.d.ts"
425425
]
426-
},
426+
],
427427
"semanticDiagnosticsPerFile": [
428428
"../../../lib/lib.d.ts",
429429
"../animals/animal.d.ts",

tests/baselines/reference/tsbuild/sample1/initial-build/explainFiles.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,11 @@ exports.someClass = someClass;
647647
"../logic/index.d.ts": 0,
648648
"./index.ts": 0
649649
},
650-
"exportedModulesMapLists": {
651-
"0": [
650+
"exportedModulesMapLists": [
651+
[
652652
"../core/anothermodule.d.ts"
653653
]
654-
},
654+
],
655655
"semanticDiagnosticsPerFile": [
656656
"../../lib/lib.d.ts",
657657
"../core/anothermodule.d.ts",

tests/baselines/reference/tsbuild/sample1/initial-build/listEmittedFiles.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,11 +572,11 @@ exports.someClass = someClass;
572572
"../logic/index.d.ts": 0,
573573
"./index.ts": 0
574574
},
575-
"exportedModulesMapLists": {
576-
"0": [
575+
"exportedModulesMapLists": [
576+
[
577577
"../core/anothermodule.d.ts"
578578
]
579-
},
579+
],
580580
"semanticDiagnosticsPerFile": [
581581
"../../lib/lib.d.ts",
582582
"../core/anothermodule.d.ts",

tests/baselines/reference/tsbuild/sample1/initial-build/listFiles.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,11 +573,11 @@ exports.someClass = someClass;
573573
"../logic/index.d.ts": 0,
574574
"./index.ts": 0
575575
},
576-
"exportedModulesMapLists": {
577-
"0": [
576+
"exportedModulesMapLists": [
577+
[
578578
"../core/anothermodule.d.ts"
579579
]
580-
},
580+
],
581581
"semanticDiagnosticsPerFile": [
582582
"../../lib/lib.d.ts",
583583
"../core/anothermodule.d.ts",

tests/baselines/reference/tsbuild/sample1/initial-build/sample.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,11 +1019,11 @@ exports.someClass = someClass;
10191019
"../logic/index.d.ts": 0,
10201020
"./index.ts": 0
10211021
},
1022-
"exportedModulesMapLists": {
1023-
"0": [
1022+
"exportedModulesMapLists": [
1023+
[
10241024
"../core/anothermodule.d.ts"
10251025
]
1026-
},
1026+
],
10271027
"semanticDiagnosticsPerFile": [
10281028
"../../lib/lib.d.ts",
10291029
"../core/anothermodule.d.ts",
@@ -1325,11 +1325,11 @@ export declare const m: typeof mod;
13251325
"../logic/decls/index.d.ts": 0,
13261326
"./index.ts": 0
13271327
},
1328-
"exportedModulesMapLists": {
1329-
"0": [
1328+
"exportedModulesMapLists": [
1329+
[
13301330
"../core/anothermodule.d.ts"
13311331
]
1332-
},
1332+
],
13331333
"semanticDiagnosticsPerFile": [
13341334
"../../lib/lib.d.ts",
13351335
"../core/anothermodule.d.ts",

tests/baselines/reference/tsbuild/watchMode/demo/updates-with-circular-reference.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,11 @@ export declare function createZoo(): Array<Dog>;
575575
],
576576
"../../zoo/zoo.ts": 0
577577
},
578-
"referencedMapLists": {
579-
"0": [
578+
"referencedMapLists": [
579+
[
580580
"../animals/index.d.ts"
581581
]
582-
},
582+
],
583583
"exportedModulesMap": {
584584
"../animals/dog.d.ts": 0,
585585
"../animals/index.d.ts": [
@@ -588,11 +588,11 @@ export declare function createZoo(): Array<Dog>;
588588
],
589589
"../../zoo/zoo.ts": 0
590590
},
591-
"exportedModulesMapLists": {
592-
"0": [
591+
"exportedModulesMapLists": [
592+
[
593593
"../animals/index.d.ts"
594594
]
595-
},
595+
],
596596
"semanticDiagnosticsPerFile": [
597597
"../../../../../../a/lib/lib.d.ts",
598598
"../animals/animal.d.ts",

tests/baselines/reference/tsbuild/watchMode/programUpdates/incremental-updates-in-verbose-mode.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -798,11 +798,11 @@ export declare function someFn(): void;
798798
"../logic/index.d.ts": 0,
799799
"./index.ts": 0
800800
},
801-
"exportedModulesMapLists": {
802-
"0": [
801+
"exportedModulesMapLists": [
802+
[
803803
"../core/anothermodule.d.ts"
804804
]
805-
},
805+
],
806806
"semanticDiagnosticsPerFile": [
807807
"../../../../../a/lib/lib.d.ts",
808808
"../core/anothermodule.d.ts",

tests/baselines/reference/tsbuild/watchMode/programUpdates/with-circular-project-reference/change-builds-changes-and-reports-found-errors-message.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -712,11 +712,11 @@ exitCode:: ExitStatus.undefined
712712
"../logic/index.d.ts": 0,
713713
"./index.ts": 0
714714
},
715-
"exportedModulesMapLists": {
716-
"0": [
715+
"exportedModulesMapLists": [
716+
[
717717
"../core/anothermodule.d.ts"
718718
]
719-
},
719+
],
720720
"semanticDiagnosticsPerFile": [
721721
"../../../../../a/lib/lib.d.ts",
722722
"../core/anothermodule.d.ts",
@@ -1046,11 +1046,11 @@ exitCode:: ExitStatus.undefined
10461046
"../logic/index.d.ts": 0,
10471047
"./index.ts": 0
10481048
},
1049-
"exportedModulesMapLists": {
1050-
"0": [
1049+
"exportedModulesMapLists": [
1050+
[
10511051
"../core/anothermodule.d.ts"
10521052
]
1053-
},
1053+
],
10541054
"semanticDiagnosticsPerFile": [
10551055
"../../../../../a/lib/lib.d.ts",
10561056
"../core/anothermodule.d.ts",
@@ -1398,11 +1398,11 @@ exitCode:: ExitStatus.undefined
13981398
"../logic/index.d.ts": 0,
13991399
"./index.ts": 0
14001400
},
1401-
"exportedModulesMapLists": {
1402-
"0": [
1401+
"exportedModulesMapLists": [
1402+
[
14031403
"../core/anothermodule.d.ts"
14041404
]
1405-
},
1405+
],
14061406
"semanticDiagnosticsPerFile": [
14071407
"../../../../../a/lib/lib.d.ts",
14081408
"../core/anothermodule.d.ts",

tests/baselines/reference/tsbuild/watchMode/programUpdates/with-simple-project-reference-graph/change-builds-changes-and-reports-found-errors-message.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -752,11 +752,11 @@ exitCode:: ExitStatus.undefined
752752
"../logic/index.d.ts": 0,
753753
"./index.ts": 0
754754
},
755-
"exportedModulesMapLists": {
756-
"0": [
755+
"exportedModulesMapLists": [
756+
[
757757
"../core/anothermodule.d.ts"
758758
]
759-
},
759+
],
760760
"semanticDiagnosticsPerFile": [
761761
"../../../../../a/lib/lib.d.ts",
762762
"../core/anothermodule.d.ts",
@@ -1092,11 +1092,11 @@ exitCode:: ExitStatus.undefined
10921092
"../logic/index.d.ts": 0,
10931093
"./index.ts": 0
10941094
},
1095-
"exportedModulesMapLists": {
1096-
"0": [
1095+
"exportedModulesMapLists": [
1096+
[
10971097
"../core/anothermodule.d.ts"
10981098
]
1099-
},
1099+
],
11001100
"semanticDiagnosticsPerFile": [
11011101
"../../../../../a/lib/lib.d.ts",
11021102
"../core/anothermodule.d.ts",
@@ -1450,11 +1450,11 @@ exitCode:: ExitStatus.undefined
14501450
"../logic/index.d.ts": 0,
14511451
"./index.ts": 0
14521452
},
1453-
"exportedModulesMapLists": {
1454-
"0": [
1453+
"exportedModulesMapLists": [
1454+
[
14551455
"../core/anothermodule.d.ts"
14561456
]
1457-
},
1457+
],
14581458
"semanticDiagnosticsPerFile": [
14591459
"../../../../../a/lib/lib.d.ts",
14601460
"../core/anothermodule.d.ts",

0 commit comments

Comments
 (0)