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

Support Fixed Size Solidity Arrays in the SDK #20

Merged
merged 12 commits into from
Sep 6, 2023
Prev Previous commit
tweak docstring
rachel-bousfield committed Sep 6, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 1398a1b4a636801347876cf222cdc1d69c529556
14 changes: 6 additions & 8 deletions stylus-sdk/src/storage/array.rs
Original file line number Diff line number Diff line change
@@ -103,17 +103,15 @@ impl<S: StorageType, const N: usize> StorageArray<S, N> {
32 / S::SLOT_BYTES
}

/// Required slots for the storage array. A maximum of either N * S::REQUIRED_SLOTS,
/// or ceil(N / density), as there are items that can fit multiple times
/// in a single slot.
/// Required slots for the storage array.
const fn required_slots() -> usize {
let left = N * S::REQUIRED_SLOTS;
let reserved = N * S::REQUIRED_SLOTS;
let density = Self::density();
let right = (N + density - 1) / density; // ceil division.
if left > right {
return left;
let packed = (N + density - 1) / density; // ceil division for packed items.
if reserved > packed {
return reserved;
}
right
packed
}
}