Merge pull request #7441 from webpack/perf/mutate-reasons
more performant changing of reasons
This commit is contained in:
commit
3415a98330
|
@ -106,6 +106,7 @@ class SideEffectsFlagPlugin {
|
|||
for (const pair of reexportMaps) {
|
||||
const module = pair[0];
|
||||
const map = pair[1];
|
||||
let newReasons = undefined;
|
||||
for (let i = 0; i < module.reasons.length; i++) {
|
||||
const reason = module.reasons[i];
|
||||
const dep = reason.dependency;
|
||||
|
@ -117,7 +118,6 @@ class SideEffectsFlagPlugin {
|
|||
if (mapping) {
|
||||
dep.redirectedModule = mapping.module;
|
||||
dep.redirectedId = mapping.exportName;
|
||||
module.reasons.splice(i--, 1);
|
||||
mapping.module.addReason(
|
||||
reason.module,
|
||||
dep,
|
||||
|
@ -126,8 +126,18 @@ class SideEffectsFlagPlugin {
|
|||
" (skipped side-effect-free modules)"
|
||||
: "(skipped side-effect-free modules)"
|
||||
);
|
||||
// removing the currect reason, by not adding it to the newReasons array
|
||||
// lazily create the newReasons array
|
||||
if (newReasons === undefined) {
|
||||
newReasons = i === 0 ? [] : module.reasons.slice(0, i);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (newReasons !== undefined) newReasons.push(reason);
|
||||
}
|
||||
if (newReasons !== undefined) {
|
||||
module.reasons = newReasons;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue