diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-11-21 15:12:58 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-12-07 00:31:06 +0100 |
commit | 2a0ec9c6459f50301a989a6df1b89358c3a9158c (patch) | |
tree | f748a2f2009980ea9d0813e6493d7ed2ce7788df /lib | |
parent | 5d2944d7b65840766bd8c4efef0af4e2680c0166 (diff) | |
download | android-node-v8-2a0ec9c6459f50301a989a6df1b89358c3a9158c.tar.gz android-node-v8-2a0ec9c6459f50301a989a6df1b89358c3a9158c.tar.bz2 android-node-v8-2a0ec9c6459f50301a989a6df1b89358c3a9158c.zip |
util: improve inspect's customInspect performance
This improves the performance to copy user options that are then
passed through to the custom inspect function.
The performance improvement depends on the complexity of the custom
inspect function. For very basic cases this is 100% faster than
before.
PR-URL: https://github.com/nodejs/node/pull/30659
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/util/inspect.js | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index dde2066294..3664c15484 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -119,6 +119,8 @@ const builtInObjects = new Set( ObjectGetOwnPropertyNames(global).filter((e) => /^([A-Z][a-z]+)+$/.test(e)) ); +// These options must stay in sync with `getUserOptions`. So if any option will +// be added or removed, `getUserOptions` must also be updated accordingly. const inspectDefaultOptions = ObjectSeal({ showHidden: false, depth: 2, @@ -176,13 +178,20 @@ const meta = [ ]; function getUserOptions(ctx) { - const obj = { stylize: ctx.stylize }; - for (const key of ObjectKeys(inspectDefaultOptions)) { - obj[key] = ctx[key]; - } - if (ctx.userOptions === undefined) - return obj; - return { ...obj, ...ctx.userOptions }; + return { + stylize: ctx.stylize, + showHidden: ctx.showHidden, + depth: ctx.depth, + colors: ctx.colors, + customInspect: ctx.customInspect, + showProxy: ctx.showProxy, + maxArrayLength: ctx.maxArrayLength, + breakLength: ctx.breakLength, + compact: ctx.compact, + sorted: ctx.sorted, + getters: ctx.getters, + ...ctx.userOptions + }; } /** |