From bf1a93f44422d6f048f185d36d30f5acb76d5d94 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Wed, 17 Apr 2019 14:00:00 +1000 Subject: [PATCH] Allocate correctly for tree hash --- eth2/utils/tree_hash_derive/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eth2/utils/tree_hash_derive/src/lib.rs b/eth2/utils/tree_hash_derive/src/lib.rs index 4b7761f91..343287313 100644 --- a/eth2/utils/tree_hash_derive/src/lib.rs +++ b/eth2/utils/tree_hash_derive/src/lib.rs @@ -166,11 +166,12 @@ pub fn tree_hash_signed_root_derive(input: TokenStream) -> TokenStream { }; let idents = get_signed_root_named_field_idents(&struct_data); + let num_elems = idents.len(); let output = quote! { impl tree_hash::SignedRoot for #name { fn signed_root(&self) -> Vec { - let mut leaves = Vec::with_capacity(4 * tree_hash::HASHSIZE); + let mut leaves = Vec::with_capacity(#num_elems * tree_hash::HASHSIZE); #( leaves.append(&mut self.#idents.tree_hash_root());