clippy linter fixes
MODIFY
storage/src/block_storage.rs
storage/src/block_storage.rs
@@ -626,11 +626,11 @@ mod tests {
.unwrap();
let index = BlockByLevelIndex::new(Arc::new(db));
- for i in vec![1161, 66441, 905, 66185, 649, 65929, 393, 65673] {
+ for i in [1161, 66441, 905, 66185, 649, 65929, 393, 65673].iter() {
index.put(
- i,
+ *i,
&BlockStorageColumnsLocation {
- block_header: Location::new(i as u64),
+ block_header: Location::new(*i as u64),
block_json_data: None,
block_additional_data: None,
},

MODIFY
storage/src/context_action_storage.rs
storage/src/context_action_storage.rs
@@ -133,13 +133,11 @@ impl ContextActionStorage {
sorted_intersect::sorted_intersect(iterators, limit.unwrap_or(std::usize::MAX))
.into_iter(),
)
- } else {
- if let Some(limit) = limit {
+ } else if let Some(limit) = limit {
self.load_indexes(base_iterator.take(limit))
} else {
self.load_indexes(base_iterator)
}
- }
} else {
let mut base_iterator = self
.context_by_contract_index
@@ -162,15 +160,13 @@ impl ContextActionStorage {
} else {
Ok(Default::default())
}
- } else {
- if let Some(limit) = limit {
+ } else if let Some(limit) = limit {
self.load_indexes(base_iterator.take(limit))
} else {
self.load_indexes(base_iterator)
}
}
}
- }
#[inline]
pub fn get_by_block_hash(
@@ -694,11 +690,11 @@ impl ContextActionByTypeIndex {
}
#[inline]
- fn get_by_action_type_iterator<'a>(
- &'a self,
+ fn get_by_action_type_iterator(
+ &self,
action_type: ContextActionType,
cursor_id: Option<SequenceNumber>,
- ) -> Result<impl Iterator<Item = u64> + 'a, StorageError> {
+ ) -> Result<impl Iterator<Item = u64> + '_, StorageError> {
let iterate_from_key = cursor_id.map_or_else(
|| ContextActionByTypeIndexKey::from_action_type_prefix(action_type),
|cursor_id| ContextActionByTypeIndexKey::new(action_type, cursor_id),
@@ -996,11 +992,7 @@ pub mod sorted_intersect {
})
});
- if let Some((_, true)) = value {
- true
- } else {
- false
- }
+ matches!(value, Some((_, true)))
}
}
@@ -1020,7 +1012,8 @@ mod tests {
};
let encoded_bytes = expected.encode()?;
let decoded = ContextActionByContractIndexKey::decode(&encoded_bytes)?;
- Ok(assert_eq!(expected, decoded))
+ assert_eq!(expected, decoded);
+ Ok(())
}
#[test]
@@ -1031,7 +1024,8 @@ mod tests {
};
let encoded_bytes = expected.encode()?;
let decoded = ContextActionByBlockHashKey::decode(&encoded_bytes)?;
- Ok(assert_eq!(expected, decoded))
+ assert_eq!(expected, decoded);
+ Ok(())
}
#[test]
@@ -1042,7 +1036,8 @@ mod tests {
};
let encoded_bytes = expected.encode()?;
let decoded = ContextActionByBlockHashKey::decode(&encoded_bytes)?;
- Ok(assert_eq!(expected, decoded))
+ assert_eq!(expected, decoded);
+ Ok(())
}
#[test]
@@ -1058,10 +1053,11 @@ mod tests {
}
.encode()?;
- Ok(assert_eq!(
+ assert_eq!(
Ordering::Less,
ContextActionByContractIndexKey::reverse_id_comparator(&a, &b)
- ))
+ );
+ Ok(())
}
#[test]

MODIFY
storage/src/merkle_storage.rs
storage/src/merkle_storage.rs
//! ``
//!
//! Reference: https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
-use hex;
use std::array::TryFromSliceError;
+use std::collections::hash_map::Entry as MapEntry;
use std::collections::{BTreeMap, HashMap};
use std::convert::TryInto;
use std::hash::Hash;
@@ -955,16 +955,18 @@ impl MerkleStorage {
let tree_is_empty = tree.is_empty();
- // Add mapping from hash to index
- if self.staged_indices.contains_key(&new_tree_hash) {
+ match self.staged_indices.entry(new_tree_hash) {
+ MapEntry::Occupied(_) => {
// entry already exists in staging, increase its refcnt only
// staged_indices will point to the other entry while this entry will be
// unreachable (wasting space, but removing it would require changing all
// other indices)
self.increase_refcnt_for_staging_entry(&new_tree_hash)?;
- } else {
+ }
+ MapEntry::Vacant(_) => {
self.staged_indices.insert(new_tree_hash, idx);
}
+ }
if tree_is_empty {
// last element was removed, delete this node
@@ -1267,7 +1269,7 @@ impl MerkleStorage {
self.last_commit_hash
}
- fn get_staged_entries(&self) -> std::string::String {
+ pub fn get_staged_entries(&self) -> std::string::String {
let mut result = String::new();
for (hash, _, entry) in &self.staged {
match entry {
@@ -1303,7 +1305,7 @@ impl MerkleStorage {
}
}
}
- return result;
+ result
}
/// Get various merkle storage statistics
@@ -1396,11 +1398,11 @@ impl MerkleStorage {
#[cfg(test)]
#[allow(unused_must_use)]
mod tests {
- use std::path::{Path, PathBuf};
- use std::{env, fs};
-
+ // use hex;
use assert_json_diff::assert_json_eq;
use rocksdb::{Options, DB};
+ use std::path::{Path, PathBuf};
+ use std::{env, fs};
use super::*;
@@ -1703,13 +1705,13 @@ mod tests {
}
fn get_short_hash(hash: &EntryHash) -> String {
- return hex::encode(&hash[0..3]);
+ hex::encode(&hash[0..3])
}
fn get_staged_root_short_hash(storage: &mut MerkleStorage) -> String {
let tree = storage.get_staged_root().unwrap();
let hash = hash_tree(&tree).unwrap();
- return get_short_hash(&hash);
+ get_short_hash(&hash)
}
#[test]

MODIFY
storage/src/operations_meta_storage.rs
storage/src/operations_meta_storage.rs
@@ -303,7 +303,8 @@ mod tests {
};
let encoded_bytes = expected.encode()?;
let decoded = Meta::decode(&encoded_bytes)?;
- Ok(assert_eq!(expected, decoded))
+ assert_eq!(expected, decoded);
+ Ok(())
}
#[test]

MODIFY
storage/src/operations_storage.rs
storage/src/operations_storage.rs
@@ -185,6 +185,7 @@ mod tests {
};
let encoded_bytes = expected.encode()?;
let decoded = OperationKey::decode(&encoded_bytes)?;
- Ok(assert_eq!(expected, decoded))
+ assert_eq!(expected, decoded);
+ Ok(())
}
}

MODIFY
storage/src/persistent/sequence.rs
storage/src/persistent/sequence.rs
// Copyright (c) SimpleStaking and Tezedge Contributors
// SPDX-License-Identifier: MIT
+use failure::Fail;
+use std::cmp::Ordering as Ord;
use std::collections::HashMap;
use std::sync::atomic::{AtomicI32, AtomicU64, Ordering};
use std::sync::{Arc, Condvar, Mutex, PoisonError};
-use failure::Fail;
-
use crate::persistent::{DBError, KeyValueSchema, KeyValueStoreWithSchema};
/// Provider a system wide unique sequence generators backed by a permanent storage.
@@ -97,11 +97,13 @@ impl SequenceGenerator {
let seq = loop {
let available = self.seq_available.fetch_add(-1, Ordering::SeqCst);
- if available > 0 {
+ match available.cmp(&0) {
+ Ord::Greater => {
// no need to allocate new sequence numbers yet
let seq = self.seq_cur.fetch_add(1, Ordering::SeqCst);
break seq;
- } else if available == 0 {
+ }
+ Ord::Equal => {
// last pre-allocated sequence numbers was allocated now, we have to perform a new allocation
let seq = self.seq_cur.fetch_add(1, Ordering::SeqCst);
@@ -121,12 +123,14 @@ impl SequenceGenerator {
self.guard.1.notify_all();
break seq;
- } else {
+ }
+ Ord::Less => {
// wait until seq_available is positive number again
let _lock = self.guard.1.wait_while(self.guard.0.lock()?, |_| {
self.seq_available.load(Ordering::SeqCst) <= 0
})?;
}
+ }
};
Ok(seq)

RENAME
storage/src/skip_list/skip_list.rs
storage/src/skip_list/list.rs
@@ -49,7 +49,7 @@ impl DatabaseBackedSkipList {
let list_db: Arc<SkipListDatabase> = db;
let state = list_db
.get(&list_id)?
- .unwrap_or_else(|| SkipListState { levels: 1, len: 0 });
+ .unwrap_or(SkipListState { levels: 1, len: 0 });
Ok(Self {
list_db,
@@ -154,6 +154,8 @@ pub trait SkipList {
fn levels(&self) -> usize;
+ fn is_empty(&self) -> bool;
+
fn contains(&self, index: usize) -> bool;
}
@@ -164,6 +166,11 @@ impl SkipList for DatabaseBackedSkipList {
self.state.len
}
+ #[inline]
+ fn is_empty(&self) -> bool {
+ self.state.len > 0
+ }
+
#[inline]
fn levels(&self) -> usize {
self.state.levels
@@ -218,20 +225,16 @@ where
loop {
if let Some(value) = lane.get(pos.index(), key)? as Option<V> {
return Ok(Some(value));
- } else {
- if pos.is_edge_node() && pos.level() < highest_level {
+ } else if pos.is_edge_node() && pos.level() < highest_level {
pos = pos.higher();
lane = lane.higher_lane();
- } else {
- if pos.index() == 0 {
+ } else if pos.index() == 0 {
return Ok(None);
} else {
pos = pos.prev();
}
}
}
- }
- }
/// Push new value into the end of the list. Beware, this is operation is
/// not thread safe and should be handled with care !!!

MODIFY
storage/src/skip_list/mod.rs
storage/src/skip_list/mod.rs
pub use crate::skip_list::content::{Bucket, ListValue, SkipListError};
pub use crate::skip_list::lane::{Lane, TypedLane};
-pub use crate::skip_list::skip_list::{DatabaseBackedSkipList, SkipList, TypedSkipList};
+pub use crate::skip_list::list::{DatabaseBackedSkipList, SkipList, TypedSkipList};
mod content;
mod lane;
-mod skip_list;
+mod list;
pub(crate) const LEVEL_BASE: usize = 8;

clippy linter fixes