-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Final tweaks for PoC-2 runtime upgrade #348
Changes from 1 commit
8a7604d
efae055
459ddce
c780209
140a7b5
cf3b78a
f3a6896
48abe9b
31b3d7e
d54c322
d63772d
6cc0643
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,22 @@ impl<'a> Input for IncrementalInput<'a> { | |
| } | ||
| } | ||
|
|
||
| // TODO: only introduce this wrapper for types where it makes sense, ideally have it within the module declaration. | ||
|
|
||
| struct AppendZeroes<'a> { | ||
| input: &'a mut Input, | ||
| } | ||
|
|
||
| impl<'a> Input for AppendZeroes<'a> { | ||
| fn read(&mut self, into: &mut [u8]) -> usize { | ||
| let r = self.input.read(into); | ||
| for z in &mut into[r..] { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will panic if the slice was completely filled, won't it?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should just return an empty slice
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. interesting artifact of the slicing syntax... that |
||
| *z = 0; | ||
| }; | ||
| into.len() | ||
| } | ||
| } | ||
|
|
||
| /// Return the value of the item in storage under `key`, or `None` if there is no explicit entry. | ||
| pub fn get<T: Codec + Sized>(key: &[u8]) -> Option<T> { | ||
| let key = twox_128(key); | ||
|
|
@@ -47,7 +63,7 @@ pub fn get<T: Codec + Sized>(key: &[u8]) -> Option<T> { | |
| key: &key[..], | ||
| pos: 0, | ||
| }; | ||
| Decode::decode(&mut input).expect("storage is not null, therefore must be a valid type") | ||
| Decode::decode(&mut AppendZeroes { input: &mut input } ).expect("storage is not null, therefore must be a valid type") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Virtual dispatch here is really unnecessary and it might have a significant cost if it occurs on every call to |
||
| }) | ||
| } | ||
|
|
||
|
|
@@ -103,8 +119,7 @@ pub fn take_or_else<T: Codec + Sized, F: FnOnce() -> T>(key: &[u8], default_valu | |
|
|
||
| /// Check to see if `key` has an explicit entry in storage. | ||
| pub fn exists(key: &[u8]) -> bool { | ||
| let mut x = [0u8; 0]; | ||
| runtime_io::read_storage(&twox_128(key)[..], &mut x[..], 0).is_some() | ||
| runtime_io::exists_storage(&twox_128(key)[..]) | ||
| } | ||
|
|
||
| /// Ensure `key` has no explicit entry in storage. | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 this is turned on by default?
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.
gah