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

Make store take a list of (key, value) to "store many" #1097

Merged
merged 3 commits into from
Jul 5, 2024
Merged

Conversation

iFrostizz
Copy link
Contributor

@iFrostizz iFrostizz commented Jul 5, 2024

Closes #1096

Update store so that it takes a list of tuples, and create a new store_single to match the old behavior.
The cache is not passed by mutable reference in order to avoid the runtime cost of borrowing it mutably many times.

The only pitfall is that because the function signature of store is now fn store<V: BorshSerialize, Pairs: IntoIterator<Item = (K, &V)>, the V has to be the same consistent type across the list.

x/programs/rust/wasmlanche-sdk/src/state.rs Outdated Show resolved Hide resolved
x/programs/rust/wasmlanche-sdk/src/state.rs Outdated Show resolved Hide resolved
Comment on lines 71 to 81
fn store_internal<V: BorshSerialize>(
cache: &mut RefMut<HashMap<K, Option<Vec<u8>>>>,
key: K,
value: &V,
) -> Result<(), Error> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a good pattern to follow if there's another way to do it.

@iFrostizz iFrostizz force-pushed the store_iter branch 2 times, most recently from a08c10e to 6ab3bc0 Compare July 5, 2024 16:59
Co-authored-by: Richard Pringle <richard.pringle@avalabs.org>
Signed-off-by: Franfran <51274081+iFrostizz@users.noreply.github.com>
@iFrostizz iFrostizz merged commit 93a9e45 into main Jul 5, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Update State.store to be able to store multiple key-values
2 participants