* Processes the provided new snapshot. * @param {Snapshot} newSnapshot snapshot * @param {Set<string>} capturedFiles files to snapshot/share * @returns {void}
(newSnapshot, capturedFiles)
| 718 | * @returns {void} |
| 719 | */ |
| 720 | optimize(newSnapshot, capturedFiles) { |
| 721 | if (capturedFiles.size === 0) { |
| 722 | return; |
| 723 | } |
| 724 | /** |
| 725 | * Increase shared and store optimization entry. |
| 726 | * @param {SnapshotOptimizationEntry} entry optimization entry |
| 727 | * @returns {void} |
| 728 | */ |
| 729 | const increaseSharedAndStoreOptimizationEntry = (entry) => { |
| 730 | if (entry.children !== undefined) { |
| 731 | for (const child of entry.children) { |
| 732 | increaseSharedAndStoreOptimizationEntry(child); |
| 733 | } |
| 734 | } |
| 735 | entry.shared++; |
| 736 | storeOptimizationEntry(entry); |
| 737 | }; |
| 738 | /** |
| 739 | * Stores optimization entry. |
| 740 | * @param {SnapshotOptimizationEntry} entry optimization entry |
| 741 | * @returns {void} |
| 742 | */ |
| 743 | const storeOptimizationEntry = (entry) => { |
| 744 | for (const path of /** @type {SnapshotContent} */ ( |
| 745 | entry.snapshotContent |
| 746 | )) { |
| 747 | const old = |
| 748 | /** @type {SnapshotOptimizationEntry} */ |
| 749 | (this._map.get(path)); |
| 750 | if (old.shared < entry.shared) { |
| 751 | this._map.set(path, entry); |
| 752 | } |
| 753 | capturedFiles.delete(path); |
| 754 | } |
| 755 | }; |
| 756 | |
| 757 | /** @type {SnapshotOptimizationEntry | undefined} */ |
| 758 | let newOptimizationEntry; |
| 759 | |
| 760 | const capturedFilesSize = capturedFiles.size; |
| 761 | |
| 762 | /** @type {Set<SnapshotOptimizationEntry> | undefined} */ |
| 763 | const optimizationEntries = new Set(); |
| 764 | |
| 765 | for (const path of capturedFiles) { |
| 766 | const optimizationEntry = this._map.get(path); |
| 767 | if (optimizationEntry === undefined) { |
| 768 | if (newOptimizationEntry === undefined) { |
| 769 | newOptimizationEntry = { |
| 770 | snapshot: newSnapshot, |
| 771 | shared: 0, |
| 772 | snapshotContent: undefined, |
| 773 | children: undefined |
| 774 | }; |
| 775 | } |
| 776 | this._map.set(path, newOptimizationEntry); |
| 777 | } else { |
no test coverage detected