From e12a26dac5cb6ffd21774781c190f09a0ec23eca Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Tue, 21 Aug 2018 17:01:09 +0200 Subject: [PATCH] Replace `Duration::new()` w/ `Duration::from_nanos` (#9387) --- ethcore/light/src/net/load_timer.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/ethcore/light/src/net/load_timer.rs b/ethcore/light/src/net/load_timer.rs index 0ad962702..9612be51e 100644 --- a/ethcore/light/src/net/load_timer.rs +++ b/ethcore/light/src/net/load_timer.rs @@ -120,17 +120,15 @@ impl LoadDistribution { pub fn expected_time(&self, kind: Kind) -> Duration { let samples = self.samples.read(); samples.get(&kind).and_then(|s| { - if s.len() == 0 { return None } + if s.is_empty() { return None } - let alpha: f64 = 1f64 / s.len() as f64; - let start = s.front().expect("length known to be non-zero; qed").clone(); - let ema = s.iter().skip(1).fold(start as f64, |a, &c| { + let alpha: f64 = 1_f64 / s.len() as f64; + let start = *s.front().expect("length known to be non-zero; qed") as f64; + let ema = s.iter().skip(1).fold(start, |a, &c| { (alpha * c as f64) + ((1.0 - alpha) * a) }); - // TODO: use `Duration::from_nanos` once stable (https://github.com/rust-lang/rust/issues/46507) - let ema = ema as u64; - Some(Duration::new(ema / 1_000_000_000, (ema % 1_000_000_000) as u32)) + Some(Duration::from_nanos(ema as u64)) }).unwrap_or_else(move || hardcoded_serve_time(kind)) }