From a4e2549b87d481161a89fb77b51be3b10936e1e8 Mon Sep 17 00:00:00 2001 From: Brian White Date: Sun, 4 Aug 2019 02:15:54 -0400 Subject: [PATCH] util: improve debuglog performance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/28956 Reviewed-By: James M Snell Reviewed-By: Anto Aravinth Reviewed-By: Michaƫl Zasso Reviewed-By: Colin Ihrig Reviewed-By: Joyee Cheung Reviewed-By: Gus Caplan Reviewed-By: Trivikram Kamat --- lib/internal/util/debuglog.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/internal/util/debuglog.js b/lib/internal/util/debuglog.js index 11de25b6b436a0..87af5de8339b87 100644 --- a/lib/internal/util/debuglog.js +++ b/lib/internal/util/debuglog.js @@ -33,7 +33,7 @@ function emitWarningIfNeeded(set) { function debuglogImpl(set) { set = set.toUpperCase(); - if (!debugs[set]) { + if (debugs[set] === undefined) { if (debugEnvRegex.test(set)) { const pid = process.pid; emitWarningIfNeeded(set); @@ -42,7 +42,7 @@ function debuglogImpl(set) { process.stderr.write(format('%s %d: %s\n', set, pid, msg)); }; } else { - debugs[set] = function debug() {}; + debugs[set] = null; } } return debugs[set]; @@ -55,12 +55,13 @@ function debuglogImpl(set) { function debuglog(set) { let debug; return function(...args) { - if (!debug) { + if (debug === undefined) { // Only invokes debuglogImpl() when the debug function is // called for the first time. debug = debuglogImpl(set); } - debug(...args); + if (debug !== null) + debug(...args); }; }