diff --git a/lib/ConcatSource.js b/lib/ConcatSource.js index bfae387..48b3937 100644 --- a/lib/ConcatSource.js +++ b/lib/ConcatSource.js @@ -20,44 +20,63 @@ ConcatSource.prototype.add = function(item) { }; ConcatSource.prototype.source = function() { - return this.children.map(function(item) { - return typeof item === "string" ? item : item.source(); - }).join(""); + var source = ''; + + var children = this.children; + for(var i = 0, l = children.length; i < l; ++i) { + var item = children[i]; + source += typeof item === "string" ? item : item.source(); + } + + return source; }; ConcatSource.prototype.size = function() { - return this.children.map(function(item) { - return typeof item === "string" ? item.length : item.size(); - }).reduce(function(sum, s) { - return sum + s; - }, 0); + var size = 0; + + var children = this.children; + for(var i = 0, l = children.length; i < l; ++i) { + var item = children[i]; + size += typeof item === "string" ? item.length : item.size(); + } + + return size; }; require("./SourceAndMapMixin")(ConcatSource.prototype); ConcatSource.prototype.node = function(options) { - var node = new SourceNode(null, null, null, this.children.map(function(item) { - return typeof item === "string" ? item : item.node(options); - })); - return node; + var chunks = []; + + var children = this.children; + for(var i = 0, l = children.length; i < l; ++i) { + var item = children[i]; + chunks.push(typeof item === "string" ? item : item.node(options)); + } + + return new SourceNode(null, null, null, chunks); }; ConcatSource.prototype.listMap = function(options) { var map = new SourceListMap(); - this.children.forEach(function(item) { - if(typeof item === "string") - map.add(item); - else - map.add(item.listMap(options)); - }); + + var children = this.children; + for(var i = 0, l = children.length; i < l; ++i) { + var item = children[i]; + map.add(typeof item === "string" ? item : item.listMap(options)); + } + return map; }; ConcatSource.prototype.updateHash = function(hash) { - this.children.forEach(function(item) { - if(typeof item === "string") + var children = this.children; + for(var i = 0, l = children.length; i < l; ++i) { + var item = children[i]; + if(typeof item === "string") { hash.update(item); - else + } else { item.updateHash(hash); - }); + } + } };