allocate outgoingConnections Set only when needed

This commit is contained in:
Tobias Koppers 2019-11-08 13:07:17 +01:00
parent 61e8b44fb9
commit c9f15d654c
1 changed files with 21 additions and 12 deletions

View File

@ -21,6 +21,8 @@ const SortableSet = require("./util/SortableSet");
* @returns {string}
*/
const EMPTY_ARRAY = [];
/** @typedef {0|1|2|3|4} UsageStateType */
const UsageState = Object.freeze({
@ -646,8 +648,8 @@ class ModuleGraphModule {
constructor() {
/** @type {Set<ModuleGraphConnection>} */
this.incomingConnections = new Set();
/** @type {Set<ModuleGraphConnection>} */
this.outgoingConnections = new Set();
/** @type {Set<ModuleGraphConnection> | undefined} */
this.outgoingConnections = undefined;
/** @type {Module | null} */
this.issuer = undefined;
/** @type {(string | OptimizationBailoutFunction)[]} */
@ -785,9 +787,11 @@ class ModuleGraph {
mgd.connection = connection;
const connections = this._getModuleGraphModule(module).incomingConnections;
connections.add(connection);
const originConnections = this._getModuleGraphModule(originModule)
.outgoingConnections;
originConnections.add(connection);
const mgm = this._getModuleGraphModule(originModule);
if (mgm.outgoingConnections === undefined) {
mgm.outgoingConnections = new Set();
}
mgm.outgoingConnections.add(connection);
}
/**
@ -880,12 +884,17 @@ class ModuleGraph {
const newMgm = this._getModuleGraphModule(newModule);
// Outgoing connections
const oldConnections = oldMgm.outgoingConnections;
const newConnections = newMgm.outgoingConnections;
for (const connection of oldConnections) {
if (filterConnection(connection)) {
connection.originModule = newModule;
newConnections.add(connection);
oldConnections.delete(connection);
if (oldConnections !== undefined) {
if (newMgm.outgoingConnections === undefined) {
newMgm.outgoingConnections = new Set();
}
const newConnections = newMgm.outgoingConnections;
for (const connection of oldConnections) {
if (filterConnection(connection)) {
connection.originModule = newModule;
newConnections.add(connection);
oldConnections.delete(connection);
}
}
}
// Incoming connections
@ -980,7 +989,7 @@ class ModuleGraph {
*/
getOutgoingConnections(module) {
const connections = this._getModuleGraphModule(module).outgoingConnections;
return connections;
return connections === undefined ? EMPTY_ARRAY : connections;
}
/**