Merge pull request #7441 from webpack/perf/mutate-reasons

more performant changing of reasons
This commit is contained in:
Tobias Koppers 2018-05-31 09:29:44 +02:00 committed by GitHub
commit 3415a98330
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

View File

@ -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;
}
}
}