-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Add Array.slice and Array.splice for value type arrays
#5965
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
Add Array.slice and Array.splice for value type arrays
#5965
Conversation
🦋 Changeset detectedLatest commit: e1fbbc9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Array.slice and Array.splice for value type arrays
Walkthrough
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The only downside of this PR is that we'd need to bump pragma of Arrays.sol to 0.8.24 to support |
contracts/utils/Arrays.sol
Outdated
| uint256 length = array.length; | ||
| end = Math.min(end, length); |
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.
| uint256 length = array.length; | |
| end = Math.min(end, length); | |
| end = Math.min(end, array.length); |
Pull Request is not mergeable
This PR implements JavaScript-like
sliceandsplicefunctions for value type arrays (uint256[],bytes32[],address[]) in the OpenZeppelin Arrays library.Key features:
slice: Creates a new array containing elements from a specified range (non-mutating)splice: Modifies the original array in-place, keeping elements from a specified range (mutating)mcopyinstruction for efficient array operationsBreaking change: Requires pragma bump to
^0.8.24for Arrays and all dependent contracts to support themcopyinstruction.This addresses issue #5723 and provides developers with familiar array manipulation utilities similar to JavaScript's Array methods.
PR Checklist
npx changeset add)