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