Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7b0b5ca
design draft
xermicus Nov 2, 2023
e05f98a
basic tests
xermicus Nov 2, 2023
be69ee7
cache the length
xermicus Nov 6, 2023
65d9ea6
get and set
xermicus Nov 6, 2023
a5e04d6
Merge branch 'master' into storage-vec
xermicus Nov 15, 2023
ac73b3f
add clear
xermicus Nov 15, 2023
ab05008
add basic integration test
xermicus Nov 15, 2023
3616b6f
add fallible methods
xermicus Nov 15, 2023
3013112
tests for fallible ops
xermicus Nov 15, 2023
e29edd0
improve clear tests
xermicus Nov 15, 2023
bd03135
fmt
xermicus Nov 15, 2023
ec4e745
spellcheck
xermicus Nov 15, 2023
63f6166
fmt
xermicus Nov 15, 2023
b3a564c
do not alias
xermicus Nov 15, 2023
439f31e
spellcheck
xermicus Nov 16, 2023
45a5776
peek
xermicus Nov 16, 2023
e49b846
make example more meaningful
xermicus Nov 17, 2023
d7abe1f
Merge branch 'master' into storage-vec
xermicus Nov 17, 2023
b0980af
add to mother
xermicus Nov 17, 2023
c87ac98
rm stale toolchain files
xermicus Nov 17, 2023
afe08f0
Merge branch 'master' into storage-vec
xermicus Nov 29, 2023
f01d430
code review
xermicus Nov 29, 2023
a0257bd
impl FromIter for StorageVec
xermicus Nov 29, 2023
634f77c
clippy
xermicus Nov 29, 2023
703430a
remove unneeded impl from slice and fix UI tests
xermicus Nov 29, 2023
50271bb
bump scale dep
xermicus Nov 29, 2023
5c2cb4e
ui
xermicus Nov 29, 2023
dc24fb9
put the cached len into a cell so we do not rely on writing operation…
xermicus Nov 29, 2023
3348363
keep None length if the vec does not exist
xermicus Nov 29, 2023
2b15422
Merge branch 'master' into storage-vec
xermicus Nov 29, 2023
07e0e2b
changelog
xermicus Nov 29, 2023
b36ae42
improve peek test
xermicus Nov 29, 2023
f53eb73
add dev note regarding cached len
xermicus Nov 29, 2023
7e161ff
Merge branch 'master' into storage-vec
xermicus Nov 29, 2023
b3dc029
Merge branch 'master' into storage-vec
xermicus Nov 30, 2023
7a12c1e
Update crates/storage/src/lazy/vec.rs
xermicus Nov 30, 2023
1d9b7d2
fmt
xermicus Nov 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
code review
Signed-off-by: Cyrill Leutwiler <[email protected]>
  • Loading branch information
xermicus committed Nov 29, 2023
commit f01d43034ea9deea25a0e7da4cde940c9ab1b59c
3 changes: 3 additions & 0 deletions crates/storage/src/lazy/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ where
/// trigger additional storage reads.
#[inline]
pub fn len(&self) -> u32 {
debug_assert!(self.len_cached.is_none() || self.len.get() == self.len_cached);

self.len_cached
Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding here is that subsequent calls of len() will still call uncached len? Why not cache it here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

For that, and all other getters it would need a &mut self receiver.

Maybe could get around that with interior mutability to remove the inefficiency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I missed that. Easy to do with a Cell though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SkymanOne added it together with a test

.unwrap_or_else(|| self.len.get().unwrap_or(u32::MIN))
}
Expand Down Expand Up @@ -444,6 +446,7 @@ where
f.debug_struct("StorageVec")
.field("key", &KeyType::KEY)
.field("len", &self.len)
.field("len_cached", &self.len_cached)
.finish()
}
}
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/lazyvec-integration-test/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ mod lazyvec_integration_tests {
/// Checks whether given account is allowed to vote and didn't already
/// participate.
fn is_eligible(&self, _voter: AccountId) -> bool {
// todo
// ToDo: In production, the contract would actually verify eligible voters.
// For example, a merkle proof could be an efficient way to do this.
true
}

Expand Down