avoid creating arrays in getConnections
This commit is contained in:
parent
c0a79c0257
commit
efe0c2e610
|
@ -36,9 +36,9 @@ const createModulesListMessage = (modules, moduleGraph) => {
|
||||||
return modules
|
return modules
|
||||||
.map(m => {
|
.map(m => {
|
||||||
let message = `* ${m.identifier()}`;
|
let message = `* ${m.identifier()}`;
|
||||||
const validReasons = moduleGraph
|
const validReasons = Array.from(
|
||||||
.getIncomingConnections(m)
|
moduleGraph.getIncomingConnections(m)
|
||||||
.filter(reason => reason.originModule);
|
).filter(reason => reason.originModule);
|
||||||
|
|
||||||
if (validReasons.length > 0) {
|
if (validReasons.length > 0) {
|
||||||
message += `\n Used by ${validReasons.length} module(s), i. e.`;
|
message += `\n Used by ${validReasons.length} module(s), i. e.`;
|
||||||
|
|
|
@ -19,6 +19,19 @@ const { dirname, mkdirp } = require("./util/fs");
|
||||||
* @property {boolean | string[]} exports
|
* @property {boolean | string[]} exports
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template T
|
||||||
|
* @param {Iterable<T>} iterable iterable
|
||||||
|
* @param {function(T): boolean} filter predicate
|
||||||
|
* @returns {boolean} true, if some items match the filter predicate
|
||||||
|
*/
|
||||||
|
const someInIterable = (iterable, filter) => {
|
||||||
|
for (const item of iterable) {
|
||||||
|
if (filter(item)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
class LibManifestPlugin {
|
class LibManifestPlugin {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
@ -60,9 +73,10 @@ class LibManifestPlugin {
|
||||||
module => {
|
module => {
|
||||||
if (
|
if (
|
||||||
this.options.entryOnly &&
|
this.options.entryOnly &&
|
||||||
!moduleGraph
|
!someInIterable(
|
||||||
.getIncomingConnections(module)
|
moduleGraph.getIncomingConnections(module),
|
||||||
.some(c => c.dependency instanceof EntryDependency)
|
c => c.dependency instanceof EntryDependency
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -339,11 +339,12 @@ class Module extends DependenciesBlock {
|
||||||
* @returns {boolean} true, if the module is optional
|
* @returns {boolean} true, if the module is optional
|
||||||
*/
|
*/
|
||||||
isOptional(moduleGraph) {
|
isOptional(moduleGraph) {
|
||||||
const connections = moduleGraph.getIncomingConnections(this);
|
let hasConnections = false;
|
||||||
return (
|
for (const r of moduleGraph.getIncomingConnections(this)) {
|
||||||
connections.length > 0 &&
|
if (!r.dependency || !r.dependency.optional || !r.active) return false;
|
||||||
connections.every(r => r.dependency && r.dependency.optional && r.active)
|
hasConnections = true;
|
||||||
);
|
}
|
||||||
|
return hasConnections;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -413,7 +414,10 @@ class Module extends DependenciesBlock {
|
||||||
* @returns {boolean} true if at least one other module depends on this module
|
* @returns {boolean} true if at least one other module depends on this module
|
||||||
*/
|
*/
|
||||||
hasReasons(moduleGraph) {
|
hasReasons(moduleGraph) {
|
||||||
return moduleGraph.getIncomingConnections(this).some(c => c.active);
|
for (const c of moduleGraph.getIncomingConnections(this)) {
|
||||||
|
if (c.active) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -967,20 +967,20 @@ class ModuleGraph {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Module} module the module
|
* @param {Module} module the module
|
||||||
* @returns {ModuleGraphConnection[]} reasons why a module is included
|
* @returns {Iterable<ModuleGraphConnection>} reasons why a module is included
|
||||||
*/
|
*/
|
||||||
getIncomingConnections(module) {
|
getIncomingConnections(module) {
|
||||||
const connections = this._getModuleGraphModule(module).incomingConnections;
|
const connections = this._getModuleGraphModule(module).incomingConnections;
|
||||||
return Array.from(connections);
|
return connections;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Module} module the module
|
* @param {Module} module the module
|
||||||
* @returns {ModuleGraphConnection[]} list of outgoing connections
|
* @returns {Iterable<ModuleGraphConnection>} list of outgoing connections
|
||||||
*/
|
*/
|
||||||
getOutgoingConnections(module) {
|
getOutgoingConnections(module) {
|
||||||
const connections = this._getModuleGraphModule(module).outgoingConnections;
|
const connections = this._getModuleGraphModule(module).outgoingConnections;
|
||||||
return Array.from(connections);
|
return connections;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -97,8 +97,7 @@ class OccurrenceModuleIdsPlugin {
|
||||||
if (prioritiseInitial) {
|
if (prioritiseInitial) {
|
||||||
for (const m of modulesInOccurrenceOrder) {
|
for (const m of modulesInOccurrenceOrder) {
|
||||||
const result =
|
const result =
|
||||||
moduleGraph
|
Array.from(moduleGraph.getIncomingConnections(m))
|
||||||
.getIncomingConnections(m)
|
|
||||||
.filter(c => c.active)
|
.filter(c => c.active)
|
||||||
.reduce(countOccursInEntry, 0) +
|
.reduce(countOccursInEntry, 0) +
|
||||||
initialChunkChunkMap.get(m) +
|
initialChunkChunkMap.get(m) +
|
||||||
|
@ -109,8 +108,7 @@ class OccurrenceModuleIdsPlugin {
|
||||||
|
|
||||||
for (const m of modules) {
|
for (const m of modules) {
|
||||||
const result =
|
const result =
|
||||||
moduleGraph
|
Array.from(moduleGraph.getIncomingConnections(m))
|
||||||
.getIncomingConnections(m)
|
|
||||||
.filter(c => c.active)
|
.filter(c => c.active)
|
||||||
.reduce(countOccurs, 0) +
|
.reduce(countOccurs, 0) +
|
||||||
chunkGraph.getNumberOfModuleChunks(m) +
|
chunkGraph.getNumberOfModuleChunks(m) +
|
||||||
|
|
|
@ -34,6 +34,19 @@ const JavascriptParser = require("./JavascriptParser");
|
||||||
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
||||||
/** @typedef {import("../util/Hash")} Hash */
|
/** @typedef {import("../util/Hash")} Hash */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template T
|
||||||
|
* @param {Iterable<T>} iterable iterable
|
||||||
|
* @param {function(T): boolean} filter predicate
|
||||||
|
* @returns {boolean} true, if some items match the filter predicate
|
||||||
|
*/
|
||||||
|
const someInIterable = (iterable, filter) => {
|
||||||
|
for (const item of iterable) {
|
||||||
|
if (filter(item)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Chunk} chunk a chunk
|
* @param {Chunk} chunk a chunk
|
||||||
* @param {ChunkGraph} chunkGraph the chunk graph
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
||||||
|
@ -729,9 +742,10 @@ class JavascriptModulesPlugin {
|
||||||
)) {
|
)) {
|
||||||
if (
|
if (
|
||||||
result.allowInlineStartup &&
|
result.allowInlineStartup &&
|
||||||
moduleGraph
|
someInIterable(
|
||||||
.getIncomingConnections(entryModule)
|
moduleGraph.getIncomingConnections(entryModule),
|
||||||
.some(c => c.originModule && c.active)
|
c => c.originModule && c.active
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
buf2.push(
|
buf2.push(
|
||||||
"// This entry module is referenced by other modules so it can't be inlined"
|
"// This entry module is referenced by other modules so it can't be inlined"
|
||||||
|
|
|
@ -738,8 +738,7 @@ class ConcatenatedModule extends Module {
|
||||||
* @returns {(function(): Module)[]} imported modules in order
|
* @returns {(function(): Module)[]} imported modules in order
|
||||||
*/
|
*/
|
||||||
const getConcatenatedImports = module => {
|
const getConcatenatedImports = module => {
|
||||||
const references = moduleGraph
|
const references = Array.from(moduleGraph.getOutgoingConnections(module))
|
||||||
.getOutgoingConnections(module)
|
|
||||||
.filter(connection => {
|
.filter(connection => {
|
||||||
if (!(connection.dependency instanceof HarmonyImportDependency))
|
if (!(connection.dependency instanceof HarmonyImportDependency))
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -173,9 +173,9 @@ class ModuleConcatenationPlugin {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const incomingConnections = moduleGraph
|
const incomingConnections = Array.from(
|
||||||
.getIncomingConnections(module)
|
moduleGraph.getIncomingConnections(module)
|
||||||
.filter(connection => connection.active);
|
).filter(connection => connection.active);
|
||||||
|
|
||||||
// Module must only be used by Harmony Imports
|
// Module must only be used by Harmony Imports
|
||||||
const nonHarmonyConnections = incomingConnections.filter(
|
const nonHarmonyConnections = incomingConnections.filter(
|
||||||
|
|
|
@ -631,7 +631,7 @@ const SIMPLE_EXTRACTORS = {
|
||||||
} = context;
|
} = context;
|
||||||
object.reasons = factory.create(
|
object.reasons = factory.create(
|
||||||
`${type}.reasons`,
|
`${type}.reasons`,
|
||||||
moduleGraph.getIncomingConnections(module),
|
Array.from(moduleGraph.getIncomingConnections(module)),
|
||||||
context
|
context
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -889,8 +889,9 @@ const SIMPLE_EXTRACTORS = {
|
||||||
object.originName = origin.readableIdentifier(requestShortener);
|
object.originName = origin.readableIdentifier(requestShortener);
|
||||||
object.moduleIdentifier = module.identifier();
|
object.moduleIdentifier = module.identifier();
|
||||||
object.moduleName = module.readableIdentifier(requestShortener);
|
object.moduleName = module.readableIdentifier(requestShortener);
|
||||||
const dependencies = moduleGraph
|
const dependencies = Array.from(
|
||||||
.getIncomingConnections(module)
|
moduleGraph.getIncomingConnections(module)
|
||||||
|
)
|
||||||
.filter(c => c.resolvedOriginModule === origin && c.dependency)
|
.filter(c => c.resolvedOriginModule === origin && c.dependency)
|
||||||
.map(c => c.dependency);
|
.map(c => c.dependency);
|
||||||
object.dependencies = factory.create(
|
object.dependencies = factory.create(
|
||||||
|
|
Loading…
Reference in New Issue