summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian White <mscdex@mscdex.net>2019-08-04 02:15:54 -0400
committerBrian White <mscdex@mscdex.net>2019-08-09 18:13:30 -0400
commitef01d7cb6648b8f475714e2f9893e573d7293c16 (patch)
tree99050fcccdb14adc33a187f51678a4fd8a19f1ed
parentbf692ce1e61948be8f258402768efe280069459b (diff)
downloadandroid-node-v8-ef01d7cb6648b8f475714e2f9893e573d7293c16.tar.gz
android-node-v8-ef01d7cb6648b8f475714e2f9893e573d7293c16.tar.bz2
android-node-v8-ef01d7cb6648b8f475714e2f9893e573d7293c16.zip
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>
-rw-r--r--lib/internal/util/debuglog.js9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/internal/util/debuglog.js b/lib/internal/util/debuglog.js
index 11de25b6b4..87af5de833 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);
};
}