Skip to content

Commit f6d3f44

Browse files
Merge pull request #1265 from mintlayer/fix/clippy_173
Appease clippy 1.73
2 parents e135879 + 0b87b3f commit f6d3f44

File tree

7 files changed

+16
-12
lines changed

7 files changed

+16
-12
lines changed

common/src/chain/block/block_body/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ mod tests {
9595
}
9696

9797
fn generate_random_bytes(rng: &mut impl Rng, length: usize) -> Vec<u8> {
98-
let mut bytes = Vec::new();
99-
bytes.resize(length, 0);
98+
let mut bytes = vec![0; length];
10099
rng.fill_bytes(&mut bytes);
101100
bytes
102101
}

common/src/chain/transaction/transaction_index/tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ fn generate_random_h256(rng: &mut impl Rng) -> H256 {
212212
}
213213

214214
fn generate_random_bytes(rng: &mut impl Rng, length: usize) -> Vec<u8> {
215-
let mut bytes = Vec::new();
216-
bytes.resize(length, 0);
215+
let mut bytes = vec![0; length];
217216
rng.fill_bytes(&mut bytes);
218217
bytes
219218
}

common/src/primitives/id/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,15 @@ impl H256 {
4646
/// are viewed as a byte-array (as is the case with H256), then serializing the type will result in whatever that
4747
/// byte-array is with no regard to endianness, which is done as big-endian in H256 if seen as a number.
4848
pub fn as_bitcoin_uint256_hex(&self) -> String {
49-
self.as_bytes().iter().rev().map(|b| format!("{:02x}", b)).collect()
49+
let hex_length = self.0.len() * 2;
50+
self.as_bytes()
51+
.iter()
52+
.rev()
53+
.fold(String::with_capacity(hex_length), |mut current, b| {
54+
use std::fmt::Write;
55+
let _ = write!(current, "{b:02x}");
56+
current
57+
})
5058
}
5159

5260
pub fn into_arith_uint256(self) -> Uint256 {
@@ -132,7 +140,7 @@ impl<T: Eq> Ord for Id<T> {
132140
// We implement PartialOrd manually to avoid it getting inherited to T through PhantomData, because Id having PartialOrd doesn't mean T requiring Ord
133141
impl<T: Eq> PartialOrd for Id<T> {
134142
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
135-
self.hash.partial_cmp(&other.hash)
143+
Some(self.cmp(other))
136144
}
137145
}
138146

mempool/src/pool/tests/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub struct ValuedOutPoint {
9999

100100
impl PartialOrd for ValuedOutPoint {
101101
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
102-
other.value.partial_cmp(&self.value)
102+
Some(self.cmp(other))
103103
}
104104
}
105105

merkletree/src/merkle/proof/multi/ordered_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<T, H> Eq for NodeWithAbsOrder<'_, T, H> {}
4848

4949
impl<T, H> PartialOrd for NodeWithAbsOrder<'_, T, H> {
5050
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
51-
self.node.abs_index().partial_cmp(&other.node.abs_index())
51+
Some(self.cmp(other))
5252
}
5353
}
5454

storage/src/database/raw.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<Sch> Ord for DbMapId<Sch> {
9595

9696
impl<Sch> PartialOrd for DbMapId<Sch> {
9797
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
98-
self.idx.partial_cmp(&other.idx)
98+
Some(self.cmp(other))
9999
}
100100
}
101101

wallet/src/account/utxo_selector/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ impl PartialEq for OutputGroupOrd {
177177

178178
impl PartialOrd for OutputGroupOrd {
179179
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
180-
self.0
181-
.get_effective_value(PayFee::PayFeeWithThisCurrency)
182-
.partial_cmp(&other.0.get_effective_value(PayFee::PayFeeWithThisCurrency))
180+
Some(self.cmp(other))
183181
}
184182
}
185183

0 commit comments

Comments
 (0)