From 475e7b31f37571057c67ab31e363653d3415f49e Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Mon, 7 Nov 2016 10:46:22 -0800 Subject: [PATCH] some random optimizations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hopefully… --- debug.js | 11 +++++++---- node.js | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/debug.js b/debug.js index b475edcf..a5992a44 100644 --- a/debug.js +++ b/debug.js @@ -83,7 +83,10 @@ function debug(namespace) { if (null == self.useColors) self.useColors = exports.useColors(); if (null == self.color && self.useColors) self.color = selectColor(); - var args = Array.prototype.slice.call(arguments); + var args = new Array(arguments.length); + for (var i = 0; i < args.length; i++) { + args[i] = arguments[i]; + } args[0] = exports.coerce(args[0]); @@ -110,9 +113,9 @@ function debug(namespace) { return match; }); - if ('function' === typeof exports.formatArgs) { - args = exports.formatArgs.apply(self, args); - } + // apply env-specific formatting + args = exports.formatArgs.apply(self, args); + var logFn = enabled.log || exports.log || console.log.bind(console); logFn.apply(self, args); } diff --git a/node.js b/node.js index 01d534b0..01e9fad5 100644 --- a/node.js +++ b/node.js @@ -80,12 +80,12 @@ exports.formatters.o = exports.formatters.O = function(v) { */ function formatArgs() { - var args = []; var len = arguments.length; + var args = new Array(len); var useColors = this.useColors; var name = this.namespace; for (var i = 0; i < len; i++) { - args.push(arguments[i]); + args[i] = arguments[i]; } if (useColors) {