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

✨ DynamicArrayLib #1073

Merged
merged 12 commits into from
Sep 16, 2024
Merged

✨ DynamicArrayLib #1073

merged 12 commits into from
Sep 16, 2024

Conversation

Vectorized
Copy link
Owner

Description

Checklist

Ensure you completed all of the steps below before submitting your pull request:

  • Ran forge fmt?
  • Ran forge snapshot?
  • Ran forge test?

Pull requests with an incomplete checklist will be thrown out.

Copy link
Collaborator

@atarpara atarpara left a 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.

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))
Copy link
Collaborator

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?

Copy link
Owner Author

@Vectorized Vectorized Sep 14, 2024

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) {} {

@Vectorized
Copy link
Owner Author

If we add pop(), we may have to add the other variants like popBool()

@Vectorized Vectorized merged commit 3464d00 into main Sep 16, 2024
9 checks passed
@Vectorized Vectorized deleted the dynamicarraylib branch September 16, 2024 07:19
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