Skip to content
Permalink
Browse files

util: improve debuglog performance

PR-URL: #28956
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information...
mscdex authored and targos committed Aug 4, 2019
1 parent 1b6d7c0 commit a4e2549b87d481161a89fb77b51be3b10936e1e8
Showing with 5 additions and 4 deletions.
  1. +5 −4 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);
};
}

0 comments on commit a4e2549

Please sign in to comment.
You can’t perform that action at this time.