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

crypto: remove unnecessary buffer initialization #54046

Closed
wants to merge 1 commit into from

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Jul 25, 2024

It seems unnecessary to initialize a Buffer for non-buffer output encodings and call toString() on an empty string. If I'm not mistaken, any encoding of an empty string, returns an empty string.

@anonrig anonrig requested a review from tniessen July 25, 2024 21:02
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/crypto

@nodejs-github-bot nodejs-github-bot added crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run. labels Jul 25, 2024
@anonrig anonrig force-pushed the fix-unnecessary-buffer-init branch from c246990 to 16877cb Compare July 25, 2024 21:04
@anonrig anonrig requested a review from jasnell July 25, 2024 21:20
@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 25, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 25, 2024
@nodejs-github-bot
Copy link
Collaborator

@anonrig anonrig added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 25, 2024
@nodejs-github-bot
Copy link
Collaborator

if (outputEncoding && outputEncoding !== 'buffer')
return buf.toString(outputEncoding);
return buf;
return !outputEncoding || outputEncoding === 'buffer' ? Buffer.from('') : '';
Copy link
Member

Choose a reason for hiding this comment

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

Is this faster than Buffer.alloc(0)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants