Skip to content

Commit

Permalink
Merge pull request #32 from webpack/performance/improvements
Browse files Browse the repository at this point in the history
Performance improvements
  • Loading branch information
sokra authored Nov 25, 2017
2 parents d79f3e9 + f512fed commit 4ea8184
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions lib/ConcatSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,45 @@ const Source = require("./Source");
class ConcatSource extends Source {
constructor() {
super();
this.children = Array.prototype.slice.call(arguments);
this.children = [];
for(var i = 0; i < arguments.length; i++) {
var item = arguments[i];
if(item instanceof ConcatSource) {
var children = item.children;
for(var j = 0; j < children.length; j++)
this.children.push(children[j]);
} else {
this.children.push(item);
}
}
}

add(item) {
this.children.push(item);
if(item instanceof ConcatSource) {
var children = item.children;
for(var j = 0; j < children.length; j++)
this.children.push(children[j]);
} else {
this.children.push(item);
}
}

source() {
let source = "";
for(let i = 0, len = this.children.length; i < len; ++i) {
const child = this.children[i];
source += (typeof child === "string") ? child : child.source();
const children = this.children;
for(let i = 0; i < children.length; i++) {
const child = children[i];
source += typeof child === "string" ? child : child.source();
}
return source;
}

size() {
let size = 0;
for(let i = 0, len = this.children.length; i < len; ++i) {
const child = this.children[i];
size += (typeof child === "string") ? child.length : child.size();
const children = this.children;
for(let i = 0; i < children.length; i++) {
const child = children[i];
size += typeof child === "string" ? child.length : child.size();
}
return size;
}
Expand All @@ -45,22 +63,26 @@ class ConcatSource extends Source {

listMap(options) {
const map = new SourceListMap();
this.children.forEach(function(item) {
var children = this.children;
for(var i = 0; i < children.length; i++) {
var item = children[i];
if(typeof item === "string")
map.add(item);
else
map.add(item.listMap(options));
});
}
return map;
}

updateHash(hash) {
this.children.forEach(function(item) {
var children = this.children;
for(var i = 0; i < children.length; i++) {
var item = children[i];
if(typeof item === "string")
hash.update(item);
else
item.updateHash(hash);
});
}
}
}

Expand Down

0 comments on commit 4ea8184

Please sign in to comment.