diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-03-29 14:15:01 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-04-03 02:31:02 +0200 |
commit | 14b2db0145c6c8715a701458dfb6ac4ec664df6d (patch) | |
tree | 4a454b7b26823882b1e5f29ee6b1fd30ab6a61e3 /lib/internal/util | |
parent | 75007d64c036bba8412df71b0aa34efee161799c (diff) | |
download | android-node-v8-14b2db0145c6c8715a701458dfb6ac4ec664df6d.tar.gz android-node-v8-14b2db0145c6c8715a701458dfb6ac4ec664df6d.tar.bz2 android-node-v8-14b2db0145c6c8715a701458dfb6ac4ec664df6d.zip |
util: improve `inspect()` compact number mode
This fixes a proportion calculation for lots of short array entries
with at least one bigger one that alone makes up for more than one
fifth of all other entries together.
PR-URL: https://github.com/nodejs/node/pull/26984
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'lib/internal/util')
-rw-r--r-- | lib/internal/util/inspect.js | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index b2ac7200c4..9280e2ac5f 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -878,6 +878,7 @@ function groupArrayElements(ctx, output) { let totalLength = 0; let maxLength = 0; let i = 0; + const separatorSpace = 2; // Add 1 for the space and 1 for the separator. const dataLen = new Array(output.length); // Calculate the total length of all output entries and the individual max // entries length of all output entries. We have to remove colors first, @@ -885,19 +886,19 @@ function groupArrayElements(ctx, output) { for (; i < output.length; i++) { const len = ctx.colors ? removeColors(output[i]).length : output[i].length; dataLen[i] = len; - totalLength += len; + totalLength += len + separatorSpace; if (maxLength < len) maxLength = len; } // Add two to `maxLength` as we add a single whitespace character plus a comma // in-between two entries. - const actualMax = maxLength + 2; + const actualMax = maxLength + separatorSpace; // Check if at least three entries fit next to each other and prevent grouping // of arrays that contains entries of very different length (i.e., if a single // entry is longer than 1/5 of all other entries combined). Otherwise the // space in-between small entries would be enormous. if (actualMax * 3 + ctx.indentationLvl < ctx.breakLength && - (totalLength / maxLength > 5 || maxLength <= 6)) { + (totalLength / actualMax > 5 || maxLength <= 6)) { const approxCharHeights = 2.5; const bias = 1; |