From 7bf83a97cfb2b38856c4c39eb2a12d6e81b464d9 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Thu, 23 May 2019 23:21:29 +1000 Subject: [PATCH] Update shuffling to use new(ish) to_le_bytes fn --- .../swap_or_not_shuffle/src/get_permutated_index.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/eth2/utils/swap_or_not_shuffle/src/get_permutated_index.rs b/eth2/utils/swap_or_not_shuffle/src/get_permutated_index.rs index 37a82341ec..f6b8065f89 100644 --- a/eth2/utils/swap_or_not_shuffle/src/get_permutated_index.rs +++ b/eth2/utils/swap_or_not_shuffle/src/get_permutated_index.rs @@ -1,8 +1,6 @@ -use bytes::Buf; use hashing::hash; use int_to_bytes::{int_to_bytes1, int_to_bytes4}; use std::cmp::max; -use std::io::Cursor; /// Return `p(index)` in a pseudorandom permutation `p` of `0...list_size-1` with ``seed`` as entropy. /// @@ -68,9 +66,10 @@ fn hash_with_round(seed: &[u8], round: u8) -> Vec { hash(&seed[..]) } -fn bytes_to_int64(bytes: &[u8]) -> u64 { - let mut cursor = Cursor::new(bytes); - cursor.get_u64_le() +fn bytes_to_int64(slice: &[u8]) -> u64 { + let mut bytes = [0; 8]; + bytes.copy_from_slice(&slice[0..8]); + u64::from_le_bytes(bytes) } #[cfg(test)]