mirror of https://github.com/webpack/webpack.git
use SortableSet in modules
use SortableSet to keep "_chunks" sorted
This commit is contained in:
parent
747efcadf9
commit
4e5ef0d72d
|
|
@ -5,21 +5,24 @@
|
|||
"use strict";
|
||||
|
||||
const util = require("util");
|
||||
|
||||
const DependenciesBlock = require("./DependenciesBlock");
|
||||
const ModuleReason = require("./ModuleReason");
|
||||
const SortableSet = require("./util/SortableSet");
|
||||
const Template = require("./Template");
|
||||
|
||||
function byId(a, b) {
|
||||
return a.id - b.id;
|
||||
}
|
||||
|
||||
function byDebugId(a, b) {
|
||||
return a.debugId - b.debugId;
|
||||
}
|
||||
|
||||
let debugId = 1000;
|
||||
|
||||
class Module extends DependenciesBlock {
|
||||
|
||||
static sortById(a, b) {
|
||||
return a.id - b.id;
|
||||
}
|
||||
|
||||
static sortByDebugId(a, b) {
|
||||
return a.debugId - b.debugId;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.context = null;
|
||||
|
|
@ -34,9 +37,7 @@ class Module extends DependenciesBlock {
|
|||
this.used = null;
|
||||
this.usedExports = null;
|
||||
this.providedExports = null;
|
||||
this._chunks = new Set();
|
||||
this._chunksIsSorted = true;
|
||||
this._chunksIsSortedByDebugId = true;
|
||||
this._chunks = new SortableSet(undefined, Module.sortById);
|
||||
this._chunksDebugIdent = undefined;
|
||||
this.warnings = [];
|
||||
this.dependenciesWarnings = [];
|
||||
|
|
@ -59,7 +60,6 @@ class Module extends DependenciesBlock {
|
|||
this.providedExports = null;
|
||||
this._chunks.clear();
|
||||
this._chunksDebugIdent = undefined;
|
||||
this._chunksIsSorted = this._chunksIsSortedByDebugId = false;
|
||||
super.disconnect();
|
||||
}
|
||||
|
||||
|
|
@ -71,14 +71,12 @@ class Module extends DependenciesBlock {
|
|||
this.depth = null;
|
||||
this._chunks.clear();
|
||||
this._chunksDebugIdent = undefined;
|
||||
this._chunksIsSorted = this._chunksIsSortedByDebugId = false;
|
||||
super.unseal();
|
||||
}
|
||||
|
||||
addChunk(chunk) {
|
||||
this._chunks.add(chunk);
|
||||
this._chunksDebugIdent = undefined;
|
||||
this._chunksIsSorted = this._chunksIsSortedByDebugId = false;
|
||||
}
|
||||
|
||||
removeChunk(chunk) {
|
||||
|
|
@ -96,7 +94,7 @@ class Module extends DependenciesBlock {
|
|||
|
||||
getChunkIdsIdent() {
|
||||
if(this._chunksDebugIdent !== undefined) return this._chunksDebugIdent;
|
||||
this._ensureChunksSortedByDebugId();
|
||||
this._chunks.sortWith(Module.sortByDebugId);
|
||||
const chunks = this._chunks;
|
||||
const list = [];
|
||||
for(const chunk of chunks) {
|
||||
|
|
@ -130,8 +128,8 @@ class Module extends DependenciesBlock {
|
|||
|
||||
hasEqualsChunks(otherModule) {
|
||||
if(this._chunks.size !== otherModule._chunks.size) return false;
|
||||
this._ensureChunksSortedByDebugId();
|
||||
otherModule._ensureChunksSortedByDebugId();
|
||||
this._chunks.sortWith(Module.sortByDebugId);
|
||||
otherModule._chunks.sortWith(Module.sortByDebugId);
|
||||
const a = this._chunks[Symbol.iterator]();
|
||||
const b = otherModule._chunks[Symbol.iterator]();
|
||||
while(true) { // eslint-disable-line
|
||||
|
|
@ -142,20 +140,6 @@ class Module extends DependenciesBlock {
|
|||
}
|
||||
}
|
||||
|
||||
_ensureChunksSorted() {
|
||||
if(this._chunksIsSorted) return;
|
||||
this._chunks = new Set(Array.from(this._chunks).sort(byId));
|
||||
this._chunksIsSortedByDebugId = false;
|
||||
this._chunksIsSorted = true;
|
||||
}
|
||||
|
||||
_ensureChunksSortedByDebugId() {
|
||||
if(this._chunksIsSortedByDebugId) return;
|
||||
this._chunks = new Set(Array.from(this._chunks).sort(byDebugId));
|
||||
this._chunksIsSorted = false;
|
||||
this._chunksIsSortedByDebugId = true;
|
||||
}
|
||||
|
||||
addReason(module, dependency) {
|
||||
this.reasons.push(new ModuleReason(module, dependency));
|
||||
}
|
||||
|
|
@ -221,8 +205,8 @@ class Module extends DependenciesBlock {
|
|||
sortItems(sortChunks) {
|
||||
super.sortItems();
|
||||
if(sortChunks)
|
||||
this._ensureChunksSorted();
|
||||
this.reasons.sort((a, b) => byId(a.module, b.module));
|
||||
this._chunks.sort();
|
||||
this.reasons.sort((a, b) => Module.sortById(a.module, b.module));
|
||||
if(Array.isArray(this.usedExports)) {
|
||||
this.usedExports.sort();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue