From 91122d91938f137d51e7e30ef0fd341072a6bb70 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Mon, 9 Jul 2018 16:47:58 +0200 Subject: [PATCH] SeedHashCompute remove needless `new` impl (#9063) --- ethash/src/cache.rs | 2 +- ethash/src/seed_compute.rs | 17 +++++------------ ethcore/src/miner/stratum.rs | 2 +- miner/src/work_notify.rs | 2 +- rpc/src/v1/impls/eth.rs | 2 +- 5 files changed, 9 insertions(+), 16 deletions(-) diff --git a/ethash/src/cache.rs b/ethash/src/cache.rs index 21bd0e231..023e4bb46 100644 --- a/ethash/src/cache.rs +++ b/ethash/src/cache.rs @@ -91,7 +91,7 @@ impl NodeCacheBuilder { pub fn new>>(optimize_for: T) -> Self { NodeCacheBuilder { - seedhash: Arc::new(Mutex::new(SeedHashCompute::new())), + seedhash: Arc::new(Mutex::new(SeedHashCompute::default())), optimize_for: optimize_for.into().unwrap_or_default(), } } diff --git a/ethash/src/seed_compute.rs b/ethash/src/seed_compute.rs index bc6f1d51e..7a3f89b9b 100644 --- a/ethash/src/seed_compute.rs +++ b/ethash/src/seed_compute.rs @@ -19,20 +19,13 @@ use keccak::{keccak_256, H256}; use std::cell::Cell; +#[derive(Default)] pub struct SeedHashCompute { prev_epoch: Cell, prev_seedhash: Cell, } impl SeedHashCompute { - #[inline] - pub fn new() -> SeedHashCompute { - SeedHashCompute { - prev_epoch: Cell::new(0), - prev_seedhash: Cell::new([0u8; 32]), - } - } - #[inline] fn reset_cache(&self) { self.prev_epoch.set(0); @@ -77,20 +70,20 @@ mod tests { #[test] fn test_seed_compute_once() { - let seed_compute = SeedHashCompute::new(); + let seed_compute = SeedHashCompute::default(); let hash = [241, 175, 44, 134, 39, 121, 245, 239, 228, 236, 43, 160, 195, 152, 46, 7, 199, 5, 253, 147, 241, 206, 98, 43, 3, 104, 17, 40, 192, 79, 106, 162]; assert_eq!(seed_compute.hash_block_number(486382), hash); } #[test] fn test_seed_compute_zero() { - let seed_compute = SeedHashCompute::new(); + let seed_compute = SeedHashCompute::default(); assert_eq!(seed_compute.hash_block_number(0), [0u8; 32]); } #[test] fn test_seed_compute_after_older() { - let seed_compute = SeedHashCompute::new(); + let seed_compute = SeedHashCompute::default(); // calculating an older value first shouldn't affect the result let _ = seed_compute.hash_block_number(50000); let hash = [241, 175, 44, 134, 39, 121, 245, 239, 228, 236, 43, 160, 195, 152, 46, 7, 199, 5, 253, 147, 241, 206, 98, 43, 3, 104, 17, 40, 192, 79, 106, 162]; @@ -99,7 +92,7 @@ mod tests { #[test] fn test_seed_compute_after_newer() { - let seed_compute = SeedHashCompute::new(); + let seed_compute = SeedHashCompute::default(); // calculating an newer value first shouldn't affect the result let _ = seed_compute.hash_block_number(972764); let hash = [241, 175, 44, 134, 39, 121, 245, 239, 228, 236, 43, 160, 195, 152, 46, 7, 199, 5, 253, 147, 241, 206, 98, 43, 3, 104, 17, 40, 192, 79, 106, 162]; diff --git a/ethcore/src/miner/stratum.rs b/ethcore/src/miner/stratum.rs index 26fb3eae6..ca7443279 100644 --- a/ethcore/src/miner/stratum.rs +++ b/ethcore/src/miner/stratum.rs @@ -158,7 +158,7 @@ impl StratumJobDispatcher { /// New stratum job dispatcher given the miner and client fn new(miner: Weak, client: Weak) -> StratumJobDispatcher { StratumJobDispatcher { - seed_compute: Mutex::new(SeedHashCompute::new()), + seed_compute: Mutex::new(SeedHashCompute::default()), client: client, miner: miner, } diff --git a/miner/src/work_notify.rs b/miner/src/work_notify.rs index 8825fd4b6..efae26ff1 100644 --- a/miner/src/work_notify.rs +++ b/miner/src/work_notify.rs @@ -62,7 +62,7 @@ impl WorkPoster { client: fetch, remote: remote, urls: urls, - seed_compute: Mutex::new(SeedHashCompute::new()), + seed_compute: Mutex::new(SeedHashCompute::default()), } } } diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index bf781d765..d20b2feb2 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -167,7 +167,7 @@ impl EthClient