@@ -231,6 +231,8 @@ class Compilation extends Tapable {
231231 this.dependencyTemplates = new Map();
232232 this.dependencyTemplates.set("hash", "");
233233 this.childrenCounters = {};
234+ this.usedChunkIds = null;
235+ this.usedModuleIds = null;
234236
235237 this._buildingModules = new Map();
236238 this._rebuildingModules = new Map();
@@ -1289,33 +1291,25 @@ class Compilation extends Tapable {
12891291 applyModuleIds() {
12901292 const unusedIds = [];
12911293 let nextFreeModuleId = 0;
1292- const usedIds = [];
1293- // TODO consider Map when performance has improved https://gist.github.com/sokra/234c077e1299b7369461f1708519c392
1294- const usedIdMap = Object.create(null);
1294+ const usedIds = new Set();
12951295 if(this.usedModuleIds) {
12961296 Object.keys(this.usedModuleIds).forEach(key => {
12971297 const id = this.usedModuleIds[key];
1298- if(!usedIdMap[id]) {
1299- usedIds.push(id);
1300- usedIdMap[id] = true;
1301- }
1298+ usedIds.add(id);
13021299 });
13031300 }
13041301
13051302 const modules1 = this.modules;
13061303 for(let indexModule1 = 0; indexModule1 < modules1.length; indexModule1++) {
13071304 const module1 = modules1[indexModule1];
1308- if(module1.id && !usedIdMap[module1.id]) {
1309- usedIds.push(module1.id);
1310- usedIdMap[module1.id] = true;
1305+ if(module1.id !== null) {
1306+ usedIds.add(module1.id);
13111307 }
13121308 }
13131309
1314- if(usedIds.length > 0) {
1310+ if(usedIds.size > 0) {
13151311 let usedIdMax = -1;
1316- for(let index = 0; index < usedIds.length; index++) {
1317- const usedIdKey = usedIds[index];
1318-
1312+ for(const usedIdKey of usedIds) {
13191313 if(typeof usedIdKey !== "number") {
13201314 continue;
13211315 }
@@ -1326,7 +1320,7 @@ class Compilation extends Tapable {
13261320 let lengthFreeModules = nextFreeModuleId = usedIdMax + 1;
13271321
13281322 while(lengthFreeModules--) {
1329- if(!usedIdMap[ lengthFreeModules] ) {
1323+ if(!usedIds.has( lengthFreeModules) ) {
13301324 unusedIds.push(lengthFreeModules);
13311325 }
13321326 }
@@ -1609,20 +1603,20 @@ class Compilation extends Tapable {
16091603 }
16101604
16111605 checkConstraints() {
1612- const usedIds = {} ;
1606+ const usedIds = new Set() ;
16131607
16141608 const modules = this.modules;
16151609 for(let indexModule = 0; indexModule < modules.length; indexModule++) {
16161610 const moduleId = modules[indexModule].id;
1617-
1618- if(usedIds[ moduleId] )
1611+ if(moduleId === null) continue;
1612+ if(usedIds.has( moduleId) )
16191613 throw new Error(`checkConstraints: duplicate module id ${moduleId}`);
1614+ usedIds.add(moduleId);
16201615 }
16211616
16221617 const chunks = this.chunks;
16231618 for(let indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
16241619 const chunk = chunks[indexChunk];
1625-
16261620 if(chunks.indexOf(chunk) !== indexChunk)
16271621 throw new Error(`checkConstraints: duplicate chunk in compilation ${chunk.debugId}`);
16281622 chunk.checkConstraints();
0 commit comments