util: improve debuglog performance
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
bf692ce1e6
commit
ef01d7cb66
@ -33,7 +33,7 @@ function emitWarningIfNeeded(set) {
|
|||||||
|
|
||||||
function debuglogImpl(set) {
|
function debuglogImpl(set) {
|
||||||
set = set.toUpperCase();
|
set = set.toUpperCase();
|
||||||
if (!debugs[set]) {
|
if (debugs[set] === undefined) {
|
||||||
if (debugEnvRegex.test(set)) {
|
if (debugEnvRegex.test(set)) {
|
||||||
const pid = process.pid;
|
const pid = process.pid;
|
||||||
emitWarningIfNeeded(set);
|
emitWarningIfNeeded(set);
|
||||||
@ -42,7 +42,7 @@ function debuglogImpl(set) {
|
|||||||
process.stderr.write(format('%s %d: %s\n', set, pid, msg));
|
process.stderr.write(format('%s %d: %s\n', set, pid, msg));
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
debugs[set] = function debug() {};
|
debugs[set] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return debugs[set];
|
return debugs[set];
|
||||||
@ -55,11 +55,12 @@ function debuglogImpl(set) {
|
|||||||
function debuglog(set) {
|
function debuglog(set) {
|
||||||
let debug;
|
let debug;
|
||||||
return function(...args) {
|
return function(...args) {
|
||||||
if (!debug) {
|
if (debug === undefined) {
|
||||||
// Only invokes debuglogImpl() when the debug function is
|
// Only invokes debuglogImpl() when the debug function is
|
||||||
// called for the first time.
|
// called for the first time.
|
||||||
debug = debuglogImpl(set);
|
debug = debuglogImpl(set);
|
||||||
}
|
}
|
||||||
|
if (debug !== null)
|
||||||
debug(...args);
|
debug(...args);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user