Merge pull request #28 from jbnicolai/fast-js

Replaces Array.prototype.reduce with an explicit loop for performance.
This commit is contained in:
Joshua Appelman 2014-06-26 14:54:17 +02:00
commit 23eab5cdf4

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() {