-
Notifications
You must be signed in to change notification settings - Fork 648
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
Implement TypedArray.prototype.with
#1365
base: main
Are you sure you want to change the base?
Conversation
Also, as an future improvement area, is it possible to determine if an array is an rvalue (as in a temporary value, which reference to was not captured yet)? I was thinking of implementing a basic copy-ellision. If there's a way right now, I might create a follow-up PR that implements it, e.g: checks if the target array is an rvalue, and if so, changes it in-place for some non mutating methods so that we do not allocate new array on every call. This would be beneficial for cases like below:
|
@dannysu has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@robik, high level optimizations like that are definitely something we are planning for in Static Hermes, but unfortunately they are almost impossible to do ahead of time in a regular untyped JS. In regular JS, when we encounter Things change dramatically in Static Hermes:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, it looks mostly good. I've left a couple comments regarding pointer safety that will have to be fixed before we can land it.
fa46507
to
6911c97
Compare
@robik has updated the pull request. You must reimport the pull request before landing. |
6911c97
to
ec06f42
Compare
@robik has updated the pull request. You must reimport the pull request before landing. |
ec06f42
to
2586bbb
Compare
@robik has updated the pull request. You must reimport the pull request before landing. |
@robik has updated the pull request. You must reimport the pull request before landing. |
Summary
This PR implements ES2023
TypedArray.prototype.with
method. This is a follow-up of PR #1286 which addedwith
method on standardArray
prototype.See also:
TypedArray.prototype.toReversed
: ImplementTypedArray.prototype.toReversed
#1366TypedArray.prototype.toSorted
: ImplementTypedArray.prototype.toSorted
#1367I am creating separate PRs for each method in case there are any suggestions or change requests from your side, so that PRs are more independent.
Test Plan
Code is annotated with algorithm steps from EcmaScript specification for easier verification and maintenance.
I also added tests to verify that methods work as intended. There might be some more edge cases that might be covered based on your experience.