Replaces Array.prototype.reduce with a for loop.

As this is possibly the hottest code path, this speeds up average total
execution time with about 25%, benchmarking shows.
This commit is contained in:
Joshua Appelman 2014-06-26 00:15:15 +02:00
parent c8fe7c3966
commit 580fe4d718

View file

@ -34,13 +34,17 @@ function applyStyle() {
return str; return str;
} }
return applyStyle._styles.reduce(function (str, name) { var nestedStyles = applyStyle._styles;
var code = ansiStyles[name];
for (var i = 0; i < nestedStyles.length; i++) {
var code = ansiStyles[nestedStyles[i]];
// Replace any instances already present with a re-opening code // Replace any instances already present with a re-opening code
// otherwise only the part of the string until said closing code // otherwise only the part of the string until said closing code
// will be colored, and the rest will simply be 'plain'. // will be colored, and the rest will simply be 'plain'.
return code.open + str.replace(code.closeRe, code.open) + code.close; str = code.open + str.replace(code.closeRe, code.open) + code.close;
}, str) ; }
return str;
} }
function init() { function init() {