optimize double map first key hash (#2451)

* fix double map encoding it is now encoded as specified in the doc
This commit is contained in:
thiolliere
2019-05-06 08:44:36 +02:00
committed by GitHub
parent 5a820db7f5
commit b0c21da94f
6 changed files with 89 additions and 16 deletions
@@ -621,9 +621,11 @@ impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
type Query = #value_type;
fn prefix_for(k1: &#k1ty) -> Vec<u8> {
use #scrate::storage::hashed::generator::StorageHasher;
let mut key = #as_double_map::prefix().to_vec();
#scrate::codec::Encode::encode_to(k1, &mut key);
#scrate::Hashable::#hasher(&key).to_vec()
#scrate::#hasher::hash(&key[..]).to_vec()
}
fn prefix() -> &'static [u8] {
@@ -234,16 +234,6 @@ impl HasherKind {
}
}
fn into_hashable_fn(&self) -> TokenStream2 {
match self {
HasherKind::Blake2_256 => quote!( blake2_256 ),
HasherKind::Blake2_128 => quote!( blake2_128 ),
HasherKind::Twox256 => quote!( twox_256 ),
HasherKind::Twox128 => quote!( twox_128 ),
HasherKind::Twox64Concat => quote!( twox_64_concat),
}
}
fn into_metadata(&self) -> TokenStream2 {
match self {
HasherKind::Blake2_256 => quote!( StorageHasher::Blake2_256 ),
@@ -596,7 +596,7 @@ fn decl_storage_items(
i.linked_map(hasher.into_storage_hasher_struct(), key_type)
},
DeclStorageTypeInfosKind::DoubleMap { key1_type, key2_type, key2_hasher, hasher } => {
i.double_map(hasher.into_hashable_fn(), key1_type, key2_type, key2_hasher)
i.double_map(hasher.into_storage_hasher_struct(), key1_type, key2_type, key2_hasher)
},
};
impls.extend(implementation)