fix compilation warnings (#11522)

This commit is contained in:
Andronik Ordian 2020-02-26 12:58:09 +01:00 committed by GitHub
parent cd7018007e
commit ec8dbb36e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 29 additions and 35 deletions

View File

@ -63,8 +63,6 @@ extern crate vm;
extern crate account_db; extern crate account_db;
#[cfg(test)] #[cfg(test)]
extern crate ethcore_accounts as accounts; extern crate ethcore_accounts as accounts;
#[cfg(test)]
extern crate stats;
#[cfg(feature = "stratum")] #[cfg(feature = "stratum")]
extern crate ethcore_stratum; extern crate ethcore_stratum;

View File

@ -49,7 +49,7 @@ impl<T> UsingQueue<T> {
/// Return a reference to the item at the top of the queue (or `None` if the queue is empty); /// 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. /// it doesn't constitute noting that the item is used.
pub fn peek_last_ref(&self) -> Option<&T> { 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); /// Return a reference to the item at the top of the queue (or `None` if the queue is empty);
@ -72,7 +72,7 @@ impl<T> UsingQueue<T> {
} }
/// Is there anything in the queue currently? /// 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. /// Clears everything; the queue is entirely reset.
pub fn reset(&mut self) { pub fn reset(&mut self) {
@ -113,7 +113,7 @@ impl<T> UsingQueue<T> {
None None
} }
} else { } else {
self.in_use.last().into_iter().filter(|x| predicate(x)).next().cloned() self.in_use.last().into_iter().find(|x| predicate(x)).cloned()
} }
} }
} }

View File

@ -84,9 +84,9 @@ impl Bloom {
let k_num = Bloom::optimal_k_num(bitmap_bits, items_count); let k_num = Bloom::optimal_k_num(bitmap_bits, items_count);
let bitmap = BitVecJournal::new(bitmap_bits as usize); let bitmap = BitVecJournal::new(bitmap_bits as usize);
Bloom { Bloom {
bitmap: bitmap, bitmap,
bitmap_bits: bitmap_bits, bitmap_bits,
k_num: k_num, k_num,
} }
} }
@ -96,9 +96,9 @@ impl Bloom {
let bitmap_bits = (bitmap_size as u64) * 8u64; let bitmap_bits = (bitmap_size as u64) * 8u64;
let bitmap = BitVecJournal::from_parts(parts); let bitmap = BitVecJournal::from_parts(parts);
Bloom { Bloom {
bitmap: bitmap, bitmap,
bitmap_bits: bitmap_bits, bitmap_bits,
k_num: k_num, k_num,
} }
} }
@ -169,15 +169,14 @@ impl Bloom {
{ {
let mut sip = SipHasher::new(); let mut sip = SipHasher::new();
item.hash(&mut sip); item.hash(&mut sip);
let hash = sip.finish(); sip.finish()
hash
} }
fn bloom_hash(base_hash: u64, k_i: u32) -> u64 { fn bloom_hash(base_hash: u64, k_i: u32) -> u64 {
if k_i < 2 { if k_i < 2 {
base_hash base_hash
} else { } 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)
} }
} }

View File

@ -5,6 +5,7 @@ license = "GPL-3.0"
name = "len-caching-lock" name = "len-caching-lock"
version = "0.1.1" version = "0.1.1"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies] [dependencies]
parking_lot = "0.10.0" parking_lot = "0.10.0"

View File

@ -25,19 +25,15 @@
//! ## Example //! ## Example
//! //!
//! ```rust //! ```rust
//! extern crate len_caching_lock;
//! use len_caching_lock::LenCachingMutex; //! use len_caching_lock::LenCachingMutex;
//! //!
//! fn main() {
//! let vec: Vec<i32> = Vec::new(); //! let vec: Vec<i32> = Vec::new();
//! let len_caching_mutex = LenCachingMutex::new(vec); //! let len_caching_mutex = LenCachingMutex::new(vec);
//! assert_eq!(len_caching_mutex.lock().len(), len_caching_mutex.load_len()); //! assert_eq!(len_caching_mutex.lock().len(), len_caching_mutex.load_len());
//! len_caching_mutex.lock().push(0); //! len_caching_mutex.lock().push(0);
//! assert_eq!(1, len_caching_mutex.load_len()); //! assert_eq!(1, len_caching_mutex.load_len());
//! }
//! ``` //! ```
extern crate parking_lot;
use std::collections::{VecDeque, LinkedList, HashMap, BTreeMap, HashSet, BTreeSet, BinaryHeap}; use std::collections::{VecDeque, LinkedList, HashMap, BTreeMap, HashSet, BTreeSet, BinaryHeap};
use std::hash::Hash; use std::hash::Hash;
@ -66,7 +62,7 @@ impl<T> Len for LinkedList<T> {
fn len(&self) -> usize { LinkedList::len(self) } fn len(&self) -> usize { LinkedList::len(self) }
} }
impl<K: Eq + Hash, V> Len for HashMap<K, V> { impl<K: Eq + Hash, V, S: std::hash::BuildHasher> Len for HashMap<K, V, S> {
fn len(&self) -> usize { HashMap::len(self) } fn len(&self) -> usize { HashMap::len(self) }
} }
@ -74,7 +70,7 @@ impl<K, V> Len for BTreeMap<K, V> {
fn len(&self) -> usize { BTreeMap::len(self) } fn len(&self) -> usize { BTreeMap::len(self) }
} }
impl<T: Eq + Hash> Len for HashSet<T> { impl<T: Eq + Hash, S: std::hash::BuildHasher> Len for HashSet<T, S> {
fn len(&self) -> usize { HashSet::len(self) } fn len(&self) -> usize { HashSet::len(self) }
} }

View File

@ -20,7 +20,7 @@ use std::sync::atomic::Ordering;
use parking_lot::{Mutex, MutexGuard}; 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 /// Can be used in place of a [`Mutex`](../../lock_api/struct.Mutex.html) where reading `T`'s `len()` without
/// needing to lock, is advantageous. /// needing to lock, is advantageous.

View File

@ -20,7 +20,7 @@ use std::sync::atomic::Ordering;
use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; 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 /// Can be used in place of a [`RwLock`](../../lock_api/struct.RwLock.html) where
/// reading `T`'s `len()` without needing to lock, is advantageous. /// reading `T`'s `len()` without needing to lock, is advantageous.

View File

@ -20,14 +20,14 @@ lazy_static! {
pub static ref BLOCKS_SWAPPER: Swapper<'static> = Swapper::new(COMMON_RLPS, INVALID_RLPS); 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 // 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], &[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 // 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] &[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 // 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], &[160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173,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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]];

View File

@ -100,9 +100,9 @@ impl<T: Ord + Copy + ::std::fmt::Display> Histogram<T>
{ {
// Histogram of a sorted corpus if it at least spans the buckets. Bounds are left closed. // Histogram of a sorted corpus if it at least spans the buckets. Bounds are left closed.
fn create(corpus: &[T], bucket_number: usize) -> Option<Histogram<T>> { fn create(corpus: &[T], bucket_number: usize) -> Option<Histogram<T>> {
if corpus.len() < 1 { return None; } if corpus.is_empty() { return None; }
let corpus_end = corpus.last().expect("there is at least 1 element; qed").clone(); 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").clone(); 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); trace!(target: "stats", "Computing histogram from {} to {} with {} buckets.", corpus_start, corpus_end, bucket_number);
// Bucket needs to be at least 1 wide. // Bucket needs to be at least 1 wide.
let bucket_size = { let bucket_size = {
@ -126,7 +126,7 @@ impl<T: Ord + Copy + ::std::fmt::Display> Histogram<T>
bucket_bounds[bucket + 1] = bucket_end; bucket_bounds[bucket + 1] = bucket_end;
bucket_end = bucket_end + bucket_size; bucket_end = bucket_end + bucket_size;
} }
Some(Histogram { bucket_bounds: bucket_bounds, counts: counts }) Some(Histogram { bucket_bounds, counts })
} }
} }