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