diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index 340e1b81f..4987861e3 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -63,8 +63,6 @@ extern crate vm; extern crate account_db; #[cfg(test)] extern crate ethcore_accounts as accounts; -#[cfg(test)] -extern crate stats; #[cfg(feature = "stratum")] extern crate ethcore_stratum; diff --git a/miner/using-queue/src/lib.rs b/miner/using-queue/src/lib.rs index 59347a6a5..b4cff65bb 100644 --- a/miner/using-queue/src/lib.rs +++ b/miner/using-queue/src/lib.rs @@ -49,7 +49,7 @@ impl UsingQueue { /// Return a reference to the item at the top of the queue (or `None` if the queue is empty); /// it doesn't constitute noting that the item is used. pub fn peek_last_ref(&self) -> Option<&T> { - self.pending.as_ref().or(self.in_use.last()) + self.pending.as_ref().or_else(|| self.in_use.last()) } /// Return a reference to the item at the top of the queue (or `None` if the queue is empty); @@ -72,7 +72,7 @@ impl UsingQueue { } /// Is there anything in the queue currently? - pub fn is_in_use(&self) -> bool { self.in_use.len() > 0 } + pub fn is_in_use(&self) -> bool { !self.in_use.is_empty() } /// Clears everything; the queue is entirely reset. pub fn reset(&mut self) { @@ -113,7 +113,7 @@ impl UsingQueue { None } } else { - self.in_use.last().into_iter().filter(|x| predicate(x)).next().cloned() + self.in_use.last().into_iter().find(|x| predicate(x)).cloned() } } } diff --git a/util/bloom/src/lib.rs b/util/bloom/src/lib.rs index 0c67944e9..c7f3f1737 100644 --- a/util/bloom/src/lib.rs +++ b/util/bloom/src/lib.rs @@ -84,9 +84,9 @@ impl Bloom { let k_num = Bloom::optimal_k_num(bitmap_bits, items_count); let bitmap = BitVecJournal::new(bitmap_bits as usize); Bloom { - bitmap: bitmap, - bitmap_bits: bitmap_bits, - k_num: k_num, + bitmap, + bitmap_bits, + k_num, } } @@ -96,9 +96,9 @@ impl Bloom { let bitmap_bits = (bitmap_size as u64) * 8u64; let bitmap = BitVecJournal::from_parts(parts); Bloom { - bitmap: bitmap, - bitmap_bits: bitmap_bits, - k_num: k_num, + bitmap, + bitmap_bits, + k_num, } } @@ -169,15 +169,14 @@ impl Bloom { { let mut sip = SipHasher::new(); item.hash(&mut sip); - let hash = sip.finish(); - hash + sip.finish() } fn bloom_hash(base_hash: u64, k_i: u32) -> u64 { if k_i < 2 { base_hash } else { - base_hash.wrapping_add((k_i as u64).wrapping_mul(base_hash) % 0xffffffffffffffc5) + base_hash.wrapping_add((k_i as u64).wrapping_mul(base_hash) % 0xffff_ffff_ffff_ffc5) } } diff --git a/util/len-caching-lock/Cargo.toml b/util/len-caching-lock/Cargo.toml index a354c71fc..3e02dc1a2 100644 --- a/util/len-caching-lock/Cargo.toml +++ b/util/len-caching-lock/Cargo.toml @@ -5,6 +5,7 @@ license = "GPL-3.0" name = "len-caching-lock" version = "0.1.1" authors = ["Parity Technologies "] +edition = "2018" [dependencies] parking_lot = "0.10.0" diff --git a/util/len-caching-lock/src/lib.rs b/util/len-caching-lock/src/lib.rs index 18118937f..f43e7f995 100644 --- a/util/len-caching-lock/src/lib.rs +++ b/util/len-caching-lock/src/lib.rs @@ -25,19 +25,15 @@ //! ## Example //! //! ```rust -//! extern crate len_caching_lock; //! use len_caching_lock::LenCachingMutex; //! -//! fn main() { -//! let vec: Vec = Vec::new(); -//! let len_caching_mutex = LenCachingMutex::new(vec); -//! assert_eq!(len_caching_mutex.lock().len(), len_caching_mutex.load_len()); -//! len_caching_mutex.lock().push(0); -//! assert_eq!(1, len_caching_mutex.load_len()); -//! } -//! ``` +//! let vec: Vec = Vec::new(); +//! let len_caching_mutex = LenCachingMutex::new(vec); +//! assert_eq!(len_caching_mutex.lock().len(), len_caching_mutex.load_len()); +//! len_caching_mutex.lock().push(0); +//! assert_eq!(1, len_caching_mutex.load_len()); +//! ``` -extern crate parking_lot; use std::collections::{VecDeque, LinkedList, HashMap, BTreeMap, HashSet, BTreeSet, BinaryHeap}; use std::hash::Hash; @@ -66,7 +62,7 @@ impl Len for LinkedList { fn len(&self) -> usize { LinkedList::len(self) } } -impl Len for HashMap { +impl Len for HashMap { fn len(&self) -> usize { HashMap::len(self) } } @@ -74,7 +70,7 @@ impl Len for BTreeMap { fn len(&self) -> usize { BTreeMap::len(self) } } -impl Len for HashSet { +impl Len for HashSet { fn len(&self) -> usize { HashSet::len(self) } } diff --git a/util/len-caching-lock/src/mutex.rs b/util/len-caching-lock/src/mutex.rs index 2d54b48db..8f401823c 100644 --- a/util/len-caching-lock/src/mutex.rs +++ b/util/len-caching-lock/src/mutex.rs @@ -20,7 +20,7 @@ use std::sync::atomic::Ordering; use parking_lot::{Mutex, MutexGuard}; -use Len; +use crate::Len; /// Can be used in place of a [`Mutex`](../../lock_api/struct.Mutex.html) where reading `T`'s `len()` without /// needing to lock, is advantageous. diff --git a/util/len-caching-lock/src/rwlock.rs b/util/len-caching-lock/src/rwlock.rs index 6a4487d48..661b4ae1a 100644 --- a/util/len-caching-lock/src/rwlock.rs +++ b/util/len-caching-lock/src/rwlock.rs @@ -20,7 +20,7 @@ use std::sync::atomic::Ordering; use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; -use Len; +use crate::Len; /// Can be used in place of a [`RwLock`](../../lock_api/struct.RwLock.html) where /// reading `T`'s `len()` without needing to lock, is advantageous. diff --git a/util/rlp-compress/src/common.rs b/util/rlp-compress/src/common.rs index b4a526412..eb199cb3e 100644 --- a/util/rlp-compress/src/common.rs +++ b/util/rlp-compress/src/common.rs @@ -20,14 +20,14 @@ lazy_static! { pub static ref BLOCKS_SWAPPER: Swapper<'static> = Swapper::new(COMMON_RLPS, INVALID_RLPS); } -static EMPTY_RLPS: &'static [&'static [u8]] = &[ +static EMPTY_RLPS: &[&[u8]] = &[ // RLP of KECCAK_NULL_RLP &[160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33], // RLP of KECCAK_EMPTY &[160, 197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112] ]; -static COMMON_RLPS: &'static [&'static [u8]] = &[ +static COMMON_RLPS: &[&[u8]] = &[ // RLP of KECCAK_NULL_RLP &[160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33], // RLP of KECCAK_EMPTY @@ -39,4 +39,4 @@ static COMMON_RLPS: &'static [&'static [u8]] = &[ &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ]; -static INVALID_RLPS: &'static [&'static [u8]] = &[&[0x81, 0x0], &[0x81, 0x1], &[0x81, 0x2], &[0x81, 0x3], &[0x81, 0x4], &[0x81, 0x5], &[0x81, 0x6], &[0x81, 0x7], &[0x81, 0x8], &[0x81, 0x9], &[0x81, 0xa], &[0x81, 0xb], &[0x81, 0xc], &[0x81, 0xd], &[0x81, 0xe], &[0x81, 0xf], &[0x81, 0x10], &[0x81, 0x11], &[0x81, 0x12], &[0x81, 0x13], &[0x81, 0x14], &[0x81, 0x15], &[0x81, 0x16], &[0x81, 0x17], &[0x81, 0x18], &[0x81, 0x19], &[0x81, 0x1a], &[0x81, 0x1b], &[0x81, 0x1c], &[0x81, 0x1d], &[0x81, 0x1e], &[0x81, 0x1f], &[0x81, 0x20], &[0x81, 0x21], &[0x81, 0x22], &[0x81, 0x23], &[0x81, 0x24], &[0x81, 0x25], &[0x81, 0x26], &[0x81, 0x27], &[0x81, 0x28], &[0x81, 0x29], &[0x81, 0x2a], &[0x81, 0x2b], &[0x81, 0x2c], &[0x81, 0x2d], &[0x81, 0x2e], &[0x81, 0x2f], &[0x81, 0x30], &[0x81, 0x31], &[0x81, 0x32], &[0x81, 0x33], &[0x81, 0x34], &[0x81, 0x35], &[0x81, 0x36], &[0x81, 0x37], &[0x81, 0x38], &[0x81, 0x39], &[0x81, 0x3a], &[0x81, 0x3b], &[0x81, 0x3c], &[0x81, 0x3d], &[0x81, 0x3e], &[0x81, 0x3f], &[0x81, 0x40], &[0x81, 0x41], &[0x81, 0x42], &[0x81, 0x43], &[0x81, 0x44], &[0x81, 0x45], &[0x81, 0x46], &[0x81, 0x47], &[0x81, 0x48], &[0x81, 0x49], &[0x81, 0x4a], &[0x81, 0x4b], &[0x81, 0x4c], &[0x81, 0x4d], &[0x81, 0x4e], &[0x81, 0x4f], &[0x81, 0x50], &[0x81, 0x51], &[0x81, 0x52], &[0x81, 0x53], &[0x81, 0x54], &[0x81, 0x55], &[0x81, 0x56], &[0x81, 0x57], &[0x81, 0x58], &[0x81, 0x59], &[0x81, 0x5a], &[0x81, 0x5b], &[0x81, 0x5c], &[0x81, 0x5d], &[0x81, 0x5e], &[0x81, 0x5f], &[0x81, 0x60], &[0x81, 0x61], &[0x81, 0x62], &[0x81, 0x63], &[0x81, 0x64], &[0x81, 0x65], &[0x81, 0x66], &[0x81, 0x67], &[0x81, 0x68], &[0x81, 0x69], &[0x81, 0x6a], &[0x81, 0x6b], &[0x81, 0x6c], &[0x81, 0x6d], &[0x81, 0x6e], &[0x81, 0x6f], &[0x81, 0x70], &[0x81, 0x71], &[0x81, 0x72], &[0x81, 0x73], &[0x81, 0x74], &[0x81, 0x75], &[0x81, 0x76], &[0x81, 0x77], &[0x81, 0x78], &[0x81, 0x79], &[0x81, 0x7a], &[0x81, 0x7b], &[0x81, 0x7c], &[0x81, 0x7d], &[0x81, 0x7e]]; +static INVALID_RLPS: &[&[u8]] = &[&[0x81, 0x0], &[0x81, 0x1], &[0x81, 0x2], &[0x81, 0x3], &[0x81, 0x4], &[0x81, 0x5], &[0x81, 0x6], &[0x81, 0x7], &[0x81, 0x8], &[0x81, 0x9], &[0x81, 0xa], &[0x81, 0xb], &[0x81, 0xc], &[0x81, 0xd], &[0x81, 0xe], &[0x81, 0xf], &[0x81, 0x10], &[0x81, 0x11], &[0x81, 0x12], &[0x81, 0x13], &[0x81, 0x14], &[0x81, 0x15], &[0x81, 0x16], &[0x81, 0x17], &[0x81, 0x18], &[0x81, 0x19], &[0x81, 0x1a], &[0x81, 0x1b], &[0x81, 0x1c], &[0x81, 0x1d], &[0x81, 0x1e], &[0x81, 0x1f], &[0x81, 0x20], &[0x81, 0x21], &[0x81, 0x22], &[0x81, 0x23], &[0x81, 0x24], &[0x81, 0x25], &[0x81, 0x26], &[0x81, 0x27], &[0x81, 0x28], &[0x81, 0x29], &[0x81, 0x2a], &[0x81, 0x2b], &[0x81, 0x2c], &[0x81, 0x2d], &[0x81, 0x2e], &[0x81, 0x2f], &[0x81, 0x30], &[0x81, 0x31], &[0x81, 0x32], &[0x81, 0x33], &[0x81, 0x34], &[0x81, 0x35], &[0x81, 0x36], &[0x81, 0x37], &[0x81, 0x38], &[0x81, 0x39], &[0x81, 0x3a], &[0x81, 0x3b], &[0x81, 0x3c], &[0x81, 0x3d], &[0x81, 0x3e], &[0x81, 0x3f], &[0x81, 0x40], &[0x81, 0x41], &[0x81, 0x42], &[0x81, 0x43], &[0x81, 0x44], &[0x81, 0x45], &[0x81, 0x46], &[0x81, 0x47], &[0x81, 0x48], &[0x81, 0x49], &[0x81, 0x4a], &[0x81, 0x4b], &[0x81, 0x4c], &[0x81, 0x4d], &[0x81, 0x4e], &[0x81, 0x4f], &[0x81, 0x50], &[0x81, 0x51], &[0x81, 0x52], &[0x81, 0x53], &[0x81, 0x54], &[0x81, 0x55], &[0x81, 0x56], &[0x81, 0x57], &[0x81, 0x58], &[0x81, 0x59], &[0x81, 0x5a], &[0x81, 0x5b], &[0x81, 0x5c], &[0x81, 0x5d], &[0x81, 0x5e], &[0x81, 0x5f], &[0x81, 0x60], &[0x81, 0x61], &[0x81, 0x62], &[0x81, 0x63], &[0x81, 0x64], &[0x81, 0x65], &[0x81, 0x66], &[0x81, 0x67], &[0x81, 0x68], &[0x81, 0x69], &[0x81, 0x6a], &[0x81, 0x6b], &[0x81, 0x6c], &[0x81, 0x6d], &[0x81, 0x6e], &[0x81, 0x6f], &[0x81, 0x70], &[0x81, 0x71], &[0x81, 0x72], &[0x81, 0x73], &[0x81, 0x74], &[0x81, 0x75], &[0x81, 0x76], &[0x81, 0x77], &[0x81, 0x78], &[0x81, 0x79], &[0x81, 0x7a], &[0x81, 0x7b], &[0x81, 0x7c], &[0x81, 0x7d], &[0x81, 0x7e]]; diff --git a/util/stats/src/lib.rs b/util/stats/src/lib.rs index 9b42b3946..ccebcbb94 100644 --- a/util/stats/src/lib.rs +++ b/util/stats/src/lib.rs @@ -100,9 +100,9 @@ impl Histogram { // Histogram of a sorted corpus if it at least spans the buckets. Bounds are left closed. fn create(corpus: &[T], bucket_number: usize) -> Option> { - if corpus.len() < 1 { return None; } - let corpus_end = corpus.last().expect("there is at least 1 element; qed").clone(); - let corpus_start = corpus.first().expect("there is at least 1 element; qed").clone(); + if corpus.is_empty() { return None; } + let corpus_end = *corpus.last().expect("there is at least 1 element; qed"); + let corpus_start = *corpus.first().expect("there is at least 1 element; qed"); trace!(target: "stats", "Computing histogram from {} to {} with {} buckets.", corpus_start, corpus_end, bucket_number); // Bucket needs to be at least 1 wide. let bucket_size = { @@ -126,7 +126,7 @@ impl Histogram bucket_bounds[bucket + 1] = bucket_end; bucket_end = bucket_end + bucket_size; } - Some(Histogram { bucket_bounds: bucket_bounds, counts: counts }) + Some(Histogram { bucket_bounds, counts }) } }