-
Notifications
You must be signed in to change notification settings - Fork 337
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
✨ DynamicArrayLib #1073
✨ DynamicArrayLib #1073
Conversation
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.
Looks Good Everything. But i think we can add pop
method.
src/utils/DynamicArrayLib.sol
Outdated
let cap := mload(add(arrData, w)) // `mload(sub(arrData, w))`. | ||
// Extract `cap`, initializing it to zero if it is not a multiple of `prime`. | ||
cap := mul(div(cap, prime), iszero(mod(cap, prime))) | ||
let newCap := shl(5, add(1, minimum)) |
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.
Why reserving 1
extra slot?
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.
Cuz:
// Expand / Reallocate memory if required.
// Note that we need to allocate an extra word for the length.
for {} iszero(lt(newArrBytesLen, cap)) {} {
is more efficient than
// Expand / Reallocate memory if required.
// Note that we need to allocate an extra word for the length.
for {} gt(newArrBytesLen, cap) {} {
6d7b1dd
to
24d0072
Compare
If we add |
Description
✨
Checklist
Ensure you completed all of the steps below before submitting your pull request:
forge fmt
?forge snapshot
?forge test
?Pull requests with an incomplete checklist will be thrown out.