dont use slice on arguments
~21% increase with multiple arguments
This commit is contained in:
parent
42918337e5
commit
7ef6f4c48a
1 changed files with 9 additions and 1 deletions
10
index.js
10
index.js
|
|
@ -40,7 +40,15 @@ var proto = defineProps(function chalk() {}, styles);
|
||||||
|
|
||||||
function applyStyle() {
|
function applyStyle() {
|
||||||
// support varags, but simply cast to string in case there's only one arg
|
// support varags, but simply cast to string in case there's only one arg
|
||||||
var str = arguments.length === 1 ? String(arguments[0]) : [].slice.call(arguments).join(' ');
|
var args = arguments;
|
||||||
|
var argsLen = args.length;
|
||||||
|
var str = argsLen !== 0 && String(arguments[0]);
|
||||||
|
if (argsLen > 1) {
|
||||||
|
// don't slice `arguments`, it prevents v8 optimizations
|
||||||
|
for (var a = 1; a < argsLen; a++) {
|
||||||
|
str += ' ' + args[a];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!chalk.enabled || !str) {
|
if (!chalk.enabled || !str) {
|
||||||
return str;
|
return str;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue