Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: improve typed array formatting #3793

Merged
merged 1 commit into from
Nov 14, 2015

Conversation

bnoordhuis
Copy link
Member

Pretty-print typed arrays like regular arrays. Speeds up formatting by
almost 300% because it no longer stringifies the array indices.

Pretty-print ArrayBuffer and DataView as well by including byteLength,
byteOffset and buffer properties in the stringified representation.

Taggging this semver-major for now. Maybe overcautious?

CI: https://ci.nodejs.org/job/node-test-pull-request/711/

@bnoordhuis bnoordhuis added util Issues and PRs related to the built-in util module. semver-major PRs that contain breaking changes and should be released in the next major version. labels Nov 12, 2015
@@ -314,6 +315,28 @@ function formatValue(ctx, value, recurseTimes) {
keys.unshift('size');
empty = value.size === 0;
formatter = formatMap;
} else if (value instanceof ArrayBuffer) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object.keys((new ArrayBuffer(5))).length === 0. Should this be placed in the shortcut path above?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nm. overlooked the other keys additions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hah. so I wasn't loosing it:

Object.keys(new ArrayBuffer(5)).length === 0;
Object.getOwnPropertyNames(new ArrayBuffer(5)).length === 0;
Object.getOwnPropertySymbols(new ArrayBuffer(5)) === 0;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put it here because it adds a key for .byteLength but I can probably move it up and call formatProperty() directly, likewise for DataView. Good idea / bad idea?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a fast path for ArrayBuffer, PTAL.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it.

@trevnorris
Copy link
Contributor

LGTM

@bnoordhuis
Copy link
Member Author

Pretty-print typed arrays like regular arrays.  Speeds up formatting by
almost 300% because it no longer stringifies the array indices.

Pretty-print ArrayBuffer and DataView as well by including byteLength,
byteOffset and buffer properties in the stringified representation.

PR-URL: nodejs#3793
Reviewed-By: Rod Vagg <[email protected]>
@bnoordhuis bnoordhuis closed this Nov 14, 2015
@bnoordhuis bnoordhuis deleted the pretty-typed-arrays branch November 14, 2015 12:31
@bnoordhuis bnoordhuis merged commit 6cf2cff into nodejs:master Nov 14, 2015
bnoordhuis added a commit to bnoordhuis/io.js that referenced this pull request Nov 14, 2015
Pretty-print typed arrays like regular arrays.  Speeds up formatting by
almost 300% because it no longer stringifies the array indices.

Pretty-print ArrayBuffer and DataView as well by including byteLength,
byteOffset and buffer properties in the stringified representation.

PR-URL: nodejs#3793
Reviewed-By: Trevor Norris <[email protected]>
@bnoordhuis
Copy link
Member Author

Thanks for review, landed in 34a3591. Apologies, I initially landed it with the wrong Reviewed-By tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-major PRs that contain breaking changes and should be released in the next major version. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants