Skip to content

Commit

Permalink
util: improve debuglog performance
Browse files Browse the repository at this point in the history
PR-URL: #28956
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
  • Loading branch information
mscdex authored and targos committed Aug 19, 2019
1 parent 1b6d7c0 commit a4e2549
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/internal/util/debuglog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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];
Expand All @@ -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);
};
}

Expand Down

0 comments on commit a4e2549

Please sign in to comment.