Purging .derefs, fixing clippy warnings. (#1890)

* Fixing clippy warnings

* Purging derefs

* Simplifying engine derefs

* Simplifying more engine derefs
This commit is contained in:
Tomasz Drwięga
2016-08-10 16:29:40 +02:00
committed by Arkadiy Paronyan
parent 8018b69440
commit a427208f79
42 changed files with 160 additions and 182 deletions

View File

@@ -490,9 +490,9 @@ impl Hasher for PlainHasher {
}
}
/// Specialized version of HashMap with H256 keys and fast hashing function.
/// Specialized version of `HashMap` with H256 keys and fast hashing function.
pub type H256FastMap<T> = HashMap<H256, T, BuildHasherDefault<PlainHasher>>;
/// Specialized version of HashSet with H256 keys and fast hashing function.
/// Specialized version of `HashSet` with H256 keys and fast hashing function.
pub type H256FastSet = HashSet<H256, BuildHasherDefault<PlainHasher>>;
#[cfg(test)]

View File

@@ -17,7 +17,6 @@
//! Panic utilities
use std::thread;
use std::ops::DerefMut;
use std::sync::Arc;
use std::default::Default;
@@ -91,7 +90,7 @@ impl PanicHandler {
/// You should use `catch_panic` instead of calling this method explicitly.
pub fn notify_all(&self, r: String) {
let mut listeners = self.listeners.lock();
for listener in listeners.deref_mut() {
for mut listener in &mut **listeners {
listener.call(&r);
}
}

View File

@@ -787,7 +787,7 @@ impl Host {
let entry = NodeEntry { id: s.id().unwrap().clone(), endpoint: NodeEndpoint { address: address, udp_port: address.port() } };
self.nodes.write().add_node(Node::new(entry.id.clone(), entry.endpoint.clone()));
let mut discovery = self.discovery.lock();
if let Some(ref mut discovery) = *discovery.deref_mut() {
if let Some(ref mut discovery) = *discovery {
discovery.add_node(entry);
}
}

View File

@@ -46,7 +46,7 @@ impl TestProtocol {
}
pub fn got_packet(&self) -> bool {
self.packet.lock().deref()[..] == b"hello"[..]
self.packet.lock()[..] == b"hello"[..]
}
pub fn got_timeout(&self) -> bool {

View File

@@ -74,7 +74,7 @@ impl HashDB for ArchiveDB {
fn keys(&self) -> HashMap<H256, i32> {
let mut ret: HashMap<H256, i32> = HashMap::new();
for (key, _) in self.backing.iter(self.column) {
let h = H256::from_slice(key.deref());
let h = H256::from_slice(&*key);
ret.insert(h, 1);
}

View File

@@ -263,7 +263,7 @@ impl HashDB for EarlyMergeDB {
fn keys(&self) -> HashMap<H256, i32> {
let mut ret: HashMap<H256, i32> = HashMap::new();
for (key, _) in self.backing.iter(self.column) {
let h = H256::from_slice(key.deref());
let h = H256::from_slice(&*key);
ret.insert(h, 1);
}

View File

@@ -329,7 +329,7 @@ impl HashDB for OverlayRecentDB {
fn keys(&self) -> HashMap<H256, i32> {
let mut ret: HashMap<H256, i32> = HashMap::new();
for (key, _) in self.backing.iter(self.column) {
let h = H256::from_slice(key.deref());
let h = H256::from_slice(&*key);
ret.insert(h, 1);
}
@@ -348,11 +348,11 @@ impl HashDB for OverlayRecentDB {
let v = self.journal_overlay.read().backing_overlay.get(&to_short_key(key)).map(|v| v.to_vec());
match v {
Some(x) => {
Some(&self.transaction_overlay.denote(key, x).0)
Some(self.transaction_overlay.denote(key, x).0)
}
_ => {
if let Some(x) = self.payload(key) {
Some(&self.transaction_overlay.denote(key, x).0)
Some(self.transaction_overlay.denote(key, x).0)
}
else {
None
@@ -920,4 +920,4 @@ mod tests {
assert!(jdb.get(&key).is_none());
}
}
}

View File

@@ -190,7 +190,7 @@ impl JournalDB for RefCountedDB {
for remove in self.removes.drain(..) {
self.forward.remove(&remove);
}
self.forward.commit_to_batch(&batch)
self.forward.commit_to_batch(batch)
}
}

View File

@@ -421,7 +421,6 @@ mod tests {
use super::*;
use devtools::*;
use std::str::FromStr;
use std::ops::Deref;
fn test_db(config: &DatabaseConfig) {
let path = RandomTempPath::create_dir();
@@ -435,13 +434,13 @@ mod tests {
batch.put(None, &key2, b"dog").unwrap();
db.write(batch).unwrap();
assert_eq!(db.get(None, &key1).unwrap().unwrap().deref(), b"cat");
assert_eq!(&*db.get(None, &key1).unwrap().unwrap(), b"cat");
let contents: Vec<_> = db.iter(None).collect();
assert_eq!(contents.len(), 2);
assert_eq!(&*contents[0].0, key1.deref());
assert_eq!(&*contents[0].0, &*key1);
assert_eq!(&*contents[0].1, b"cat");
assert_eq!(&*contents[1].0, key2.deref());
assert_eq!(&*contents[1].0, &*key2);
assert_eq!(&*contents[1].1, b"dog");
let batch = db.transaction();
@@ -459,10 +458,10 @@ mod tests {
transaction.delete(None, &key1).unwrap();
db.write(transaction).unwrap();
assert!(db.get(None, &key1).unwrap().is_none());
assert_eq!(db.get(None, &key3).unwrap().unwrap().deref(), b"elephant");
assert_eq!(&*db.get(None, &key3).unwrap().unwrap(), b"elephant");
assert_eq!(db.get_by_prefix(None, &key3).unwrap().deref(), b"elephant");
assert_eq!(db.get_by_prefix(None, &key2).unwrap().deref(), b"dog");
assert_eq!(&*db.get_by_prefix(None, &key3).unwrap(), b"elephant");
assert_eq!(&*db.get_by_prefix(None, &key2).unwrap(), b"dog");
}
#[test]

View File

@@ -22,7 +22,6 @@ use bytes::*;
use rlp::*;
use hashdb::*;
use memorydb::*;
use std::ops::*;
use std::sync::*;
use std::collections::HashMap;
use kvdb::{Database, DBTransaction};
@@ -130,7 +129,7 @@ impl HashDB for OverlayDB {
fn keys(&self) -> HashMap<H256, i32> {
let mut ret: HashMap<H256, i32> = HashMap::new();
for (key, _) in self.backing.iter(self.column) {
let h = H256::from_slice(key.deref());
let h = H256::from_slice(&*key);
let r = self.payload(&h).unwrap().1;
ret.insert(h, r as i32);
}
@@ -305,7 +304,7 @@ fn playpen() {
batch.put(None, b"test", b"test2").unwrap();
db.write(batch).unwrap();
match db.get(None, b"test") {
Ok(Some(value)) => println!("Got value {:?}", value.deref()),
Ok(Some(value)) => println!("Got value {:?}", &*value),
Ok(None) => println!("No value for that key"),
Err(..) => println!("Gah"),
}
@@ -314,4 +313,4 @@ fn playpen() {
db.write(batch).unwrap();
}
fs::remove_dir_all("/tmp/test").unwrap();
}
}

View File

@@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::ops::Deref;
use std::default::Default;
use elastic_array::*;
use rlp::bytes::{ToBytes, VecLike};
use rlp::{Stream, Encoder, Encodable};
@@ -293,7 +291,7 @@ impl<'a> Encodable for &'a[u8] {
impl Encodable for Vec<u8> {
fn rlp_append(&self, s: &mut RlpStream) {
s.append_value(&U8Slice(self.deref()))
s.append_value(&U8Slice(self))
}
}
@@ -334,7 +332,7 @@ impl<'a, T> Encodable for &'a[T] where T: Encodable {
impl<T> Encodable for Vec<T> where T: Encodable {
fn rlp_append(&self, s: &mut RlpStream) {
Encodable::rlp_append(&self.deref(), s);
Encodable::rlp_append(&self.as_slice(), s);
}
}

View File

@@ -15,7 +15,6 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Common RLP traits
use std::ops::Deref;
use rlp::bytes::VecLike;
use rlp::{DecoderError, UntrustedRlp};
use rlp::rlpstream::RlpStream;
@@ -244,7 +243,7 @@ pub trait ByteEncodable {
fn bytes_len(&self) -> usize;
}
/// Structure encodable to RLP. Implement this trait for
/// Structure encodable to RLP. Implement this trait for
pub trait Encodable {
/// Append a value to the stream
fn rlp_append(&self, s: &mut RlpStream);
@@ -257,7 +256,7 @@ pub trait Encodable {
}
/// Get the hash or RLP encoded representation
fn rlp_sha3(&self) -> H256 { self.rlp_bytes().deref().sha3() }
fn rlp_sha3(&self) -> H256 { (&*self.rlp_bytes()).sha3() }
}
/// Encodable wrapper trait required to handle special case of encoding a &[u8] as string and not as list

View File

@@ -192,7 +192,7 @@ impl<'db> TrieDB<'db> {
where 'db: 'key
{
let root_rlp = try!(self.root_data());
self.get_from_node(&root_rlp, key)
self.get_from_node(root_rlp, key)
}
/// Recursible function to retrieve the value given a `node` and a partial `key`. `None` if no