allocate presentationalDependencies array only when needed

This commit is contained in:
Tobias Koppers 2019-11-08 15:39:44 +01:00
parent 14e901225c
commit 5abf55b1af
6 changed files with 49 additions and 22 deletions

View File

@ -55,6 +55,15 @@ class DependenciesBlock {
}
}
/**
* Removes all dependencies and blocks
* @returns {void}
*/
clearDependenciesAndBlocks() {
this.dependencies.length = 0;
this.blocks.length = 0;
}
/**
* @param {Hash} hash the hash used to track dependencies
* @param {ChunkGraph} chunkGraph the chunk graph

View File

@ -117,8 +117,8 @@ class Module extends DependenciesBlock {
this.buildMeta = undefined;
/** @type {object} */
this.buildInfo = undefined;
/** @type {Dependency[]} */
this.presentationalDependencies = [];
/** @type {Dependency[] | undefined} */
this.presentationalDependencies = undefined;
}
// TODO remove in webpack 6
@ -335,9 +335,23 @@ class Module extends DependenciesBlock {
* @returns {void}
*/
addPresentationalDependency(presentationalDependency) {
if (this.presentationalDependencies === undefined) {
this.presentationalDependencies = [];
}
this.presentationalDependencies.push(presentationalDependency);
}
/**
* Removes all dependencies and blocks
* @returns {void}
*/
clearDependenciesAndBlocks() {
if (this.presentationalDependencies !== undefined) {
this.presentationalDependencies.length = 0;
}
super.clearDependenciesAndBlocks();
}
/**
* @param {WebpackError} warning the warning
* @returns {void}
@ -551,8 +565,10 @@ class Module extends DependenciesBlock {
hash.update(exportInfo.used + "");
hash.update(exportInfo.usedName + "");
}
for (const dep of this.presentationalDependencies) {
dep.updateHash(hash, chunkGraph);
if (this.presentationalDependencies !== undefined) {
for (const dep of this.presentationalDependencies) {
dep.updateHash(hash, chunkGraph);
}
}
super.updateHash(hash, chunkGraph);
}

View File

@ -557,9 +557,7 @@ class NormalModule extends Module {
this._ast = null;
this.error = null;
this.clearWarningsAndErrors();
this.dependencies.length = 0;
this.presentationalDependencies.length = 0;
this.blocks.length = 0;
this.clearDependenciesAndBlocks();
this.buildMeta = {};
this.buildInfo = {
cacheable: false,

View File

@ -88,14 +88,16 @@ class JavascriptGenerator extends Generator {
);
}
for (const dependency of module.presentationalDependencies) {
this.sourceDependency(
module,
dependency,
initFragments,
source,
generateContext
);
if (module.presentationalDependencies !== undefined) {
for (const dependency of module.presentationalDependencies) {
this.sourceDependency(
module,
dependency,
initFragments,
source,
generateContext
);
}
}
for (const childBlock of module.blocks) {

View File

@ -573,7 +573,6 @@ class ConcatenatedModule extends Module {
// Graph
this.dependencies = [];
this.presentationalDependencies = [];
this._orderedConcatenationList = ConcatenatedModule._createConcatenationList(
rootModule,
@ -592,12 +591,14 @@ class ConcatenatedModule extends Module {
)) {
this.dependencies.push(d);
}
for (const d of m.presentationalDependencies.filter(
dep =>
!(dep instanceof HarmonyImportDependency) ||
!modules.has(compilation.moduleGraph.getModule(dep))
)) {
this.presentationalDependencies.push(d);
if (m.presentationalDependencies !== undefined) {
for (const d of m.presentationalDependencies.filter(
dep =>
!(dep instanceof HarmonyImportDependency) ||
!modules.has(compilation.moduleGraph.getModule(dep))
)) {
this.addPresentationalDependency(d);
}
}
// populate file dependencies
if (m.buildInfo.fileDependencies) {

View File

@ -113,6 +113,7 @@ class ModuleConcatenationPlugin {
if (
!module.buildMeta ||
module.buildMeta.exportsType !== "namespace" ||
module.presentationalDependencies === undefined ||
!module.presentationalDependencies.some(
d => d instanceof HarmonyCompatibilityDependency
)