Use optimized append and len storage methods in SRML. (#3071)

* expose len from codec to storage.

* refactor runtime with len and append.

* Undo example.

* Remove imports.

* Bump codec.

* Optionify.

* Make decode_len counscious.

* Refactor.

* Update srml/support/src/storage/hashed/generator.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update srml/support/src/storage/hashed/generator.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update srml/support/src/storage/hashed/generator.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update srml/support/src/storage/hashed/generator.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Fix merge.

* fix some docs.

* Add NoDefault trait.

* Bump.

* Final nits.

* Update srml/support/src/traits.rs

* new approach toward len.

* re-create lock file.

* Fix build errors and Option handling.

* More test fix

* Use default for append as well.

* Fix runtime.

* Add support for linked_map

* More tweaks from review.

* Fix style

* Change api for none-values

* Bump.
This commit is contained in:
Kian Paimani
2019-08-27 19:39:05 +02:00
committed by Bastian Köcher
parent 99a7492dbf
commit 095c7de7ff
13 changed files with 573 additions and 179 deletions
+22
View File
@@ -26,6 +26,28 @@ use crate::sr_primitives::ConsensusEngineId;
use super::for_each_tuple;
/// A trait that can return the default value of a storage item. This must only ever be implemented
/// for a special delegator struct for each storage item
pub trait StorageDefault<V>: Sized {
/// Return the default value of type `V`. `None`, if `V` does not have a proper default value.
fn default() -> Option<V>;
}
// FIXME #1466 This is needed for `storage_items!`. Should be removed once it is deprecated.
impl<T: Default> StorageDefault<T> for () { fn default() -> Option<T> { Some(Default::default()) } }
/// Anything that can have a `::len()` method.
pub trait Len {
/// Return the length of data type.
fn len(&self) -> usize;
}
impl<T: IntoIterator + Clone,> Len for T where <T as IntoIterator>::IntoIter: ExactSizeIterator {
fn len(&self) -> usize {
self.clone().into_iter().len()
}
}
/// A trait for querying a single fixed value from a type.
pub trait Get<T> {
/// Return a constant value.