MCPcopy
hub / github.com/webpack/webpack / optimize

Method optimize

lib/FileSystemInfo.js:720–937  ·  lib/FileSystemInfo.js::SnapshotOptimization.optimize

* Processes the provided new snapshot. * @param {Snapshot} newSnapshot snapshot * @param {Set<string>} capturedFiles files to snapshot/share * @returns {void}

(newSnapshot, capturedFiles)

Source from the content-addressed store, hash-verified

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 {

Callers 5

jobDoneMethod · 0.80
processCapturedFilesMethod · 0.80
createSnapshotMethod · 0.80

Calls 9

setMergedStartTimeMethod · 0.95
_getMethod · 0.80
keysMethod · 0.65
getMethod · 0.45
setMethod · 0.45
addMethod · 0.45
hasMethod · 0.45
addChildMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected