Skip to content

Commit 7edffc3

Browse files
committed
Small refactor for getting size
Currently, map is being called to extract sizes then reduce is called on that; so 2 iterations through the array. It is possible to solve this with only reduce: 1 iteration. reallyUsedModules probably won't ever be big enough for this to matter, so it comes down to readability. I think doing a once-and-done reduce could be an improvement here. What do you guys think?
1 parent d898ca8 commit 7edffc3

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

lib/optimize/CommonsChunkPlugin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ CommonsChunkPlugin.prototype.apply = function(compiler) {
114114
reallyUsedModules.push(module);
115115
});
116116
if(minSize) {
117-
var size = reallyUsedModules.map(function(module) {
118-
return module.size();
119-
}).reduce(function(a, b) { return a + b; }, 0);
117+
var size = reallyUsedModules.reduce(function(a, b) {
118+
return a + b.size();
119+
}, 0);
120120
if(size < minSize)
121121
return;
122122
}

0 commit comments

Comments
 (0)