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

Fix double allocation in typedarray-of.js #2611

Merged
merged 1 commit into from
Sep 12, 2023
Merged

Fix double allocation in typedarray-of.js #2611

merged 1 commit into from
Sep 12, 2023

Conversation

codefrau
Copy link
Contributor

Description

The current example for TypedArray.of() allocates an empty array first, before invoking the static of() method. My fix removes that unnecessary and misleading initial allocation.

Motivation

A novice user might look at the current example code and infer that they need to create a new typed array first before they can use the of() method. That is not the case. Also, simpler is better.

Additional details

I replaced

let int16array = new Int16Array();
int16array = Int16Array.of('10', '20', '30', '40', '50');

with

const int16array = Int16Array.of('10', '20', '30', '40', '50');

to avoid the unnecessary allocation of the empty array.

Related issues and pull requests

n/a

It was unnecessary and confusing to first create an empty array and then replace it with another array
@codefrau codefrau requested a review from a team as a code owner September 12, 2023 03:06
@codefrau codefrau requested review from Josh-Cena and removed request for a team September 12, 2023 03:06
@github-actions
Copy link

It looks like this is your first pull request. 🎉 Thank you for your contribution! One of the project maintainers will triage and assign the pull request for review. We appreciate your patience. To safeguard the health of the project, please take a moment to read our code of conduct.

Copy link
Member

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@Josh-Cena Josh-Cena merged commit b98aa66 into mdn:main Sep 12, 2023
5 checks passed
@github-actions
Copy link

Congratulations on your first merged pull request. 🎉 Thank you for your contribution! Did you know we have a project board with high-impact contribution opportunities? We look forward to your next contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants