diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-04-13 14:21:45 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-04-16 17:09:58 +0200 |
commit | f413f56c3606fa6f01f0a7341fb4136965890fb7 (patch) | |
tree | 1fb579994ee26a802a9e891bbb5d6ed15a5bb1a6 | |
parent | 5c425788f1087f4f41fb6174692433d1bf4ce891 (diff) | |
download | android-node-v8-f413f56c3606fa6f01f0a7341fb4136965890fb7.tar.gz android-node-v8-f413f56c3606fa6f01f0a7341fb4136965890fb7.tar.bz2 android-node-v8-f413f56c3606fa6f01f0a7341fb4136965890fb7.zip |
util: fix inspect performance bug
In case an object contained a circular reference `Object.keys` was
called even though it was not necessary at all. This caused a
significant overhead for objects that contained a lot of such entries.
PR-URL: https://github.com/nodejs/node/pull/20007
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
-rw-r--r-- | lib/util.js | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/util.js b/lib/util.js index 737ad5d0b4..762461402e 100644 --- a/lib/util.js +++ b/lib/util.js @@ -456,6 +456,11 @@ function formatValue(ctx, value, recurseTimes, ln) { } } + // Using an array here is actually better for the average case than using + // a Set. `seen` will only check for the depth and will never grow too large. + if (ctx.seen.indexOf(value) !== -1) + return ctx.stylize('[Circular]', 'special'); + let keys; let symbols = Object.getOwnPropertySymbols(value); @@ -640,11 +645,6 @@ function formatValue(ctx, value, recurseTimes, ln) { } } - // Using an array here is actually better for the average case than using - // a Set. `seen` will only check for the depth and will never grow too large. - if (ctx.seen.indexOf(value) !== -1) - return ctx.stylize('[Circular]', 'special'); - if (recurseTimes != null) { if (recurseTimes < 0) return ctx.stylize(`[${constructor || tag || 'Object'}]`, 'special'); |