Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit bb63b1c

Browse files
committed
Drop some unnecessary cloning by comparing references
1 parent 06a6d47 commit bb63b1c

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

ethcore/src/block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,14 @@ impl<'x> OpenBlock<'x> {
370370
let mut s = self;
371371

372372
s.engine.on_close_block(&mut s.block);
373-
if s.block.base.header.transactions_root().is_zero() || s.block.base.header.transactions_root().clone() == SHA3_NULL_RLP {
373+
if s.block.base.header.transactions_root().is_zero() || s.block.base.header.transactions_root() == &SHA3_NULL_RLP {
374374
s.block.base.header.set_transactions_root(ordered_trie_root(s.block.base.transactions.iter().map(|e| e.rlp_bytes().to_vec()).collect()));
375375
}
376376
let uncle_bytes = s.block.base.uncles.iter().fold(RlpStream::new_list(s.block.base.uncles.len()), |mut s, u| {s.append_raw(&u.rlp(Seal::With), 1); s} ).out();
377377
if s.block.base.header.uncles_hash().is_zero() {
378378
s.block.base.header.set_uncles_hash(uncle_bytes.sha3());
379379
}
380-
if s.block.base.header.receipts_root().is_zero() || s.block.base.header.receipts_root().clone() == SHA3_NULL_RLP {
380+
if s.block.base.header.receipts_root().is_zero() || s.block.base.header.receipts_root() == &SHA3_NULL_RLP {
381381
s.block.base.header.set_receipts_root(ordered_trie_root(s.block.receipts.iter().map(|r| r.rlp_bytes().to_vec()).collect()));
382382
}
383383
s.block.base.header.set_state_root(s.block.state.root().clone());

ethcore/src/engines/basic_authority.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl Engine for BasicAuthority {
153153
let gas_limit_divisor = self.our_params.gas_limit_bound_divisor;
154154
let min_gas = parent.gas_limit().clone() - parent.gas_limit().clone() / gas_limit_divisor;
155155
let max_gas = parent.gas_limit().clone() + parent.gas_limit().clone() / gas_limit_divisor;
156-
if header.gas_limit().clone() <= min_gas || header.gas_limit().clone() >= max_gas {
156+
if header.gas_limit() <= &min_gas || header.gas_limit() >= &max_gas {
157157
return Err(From::from(BlockError::InvalidGasLimit(OutOfBounds { min: Some(min_gas), max: Some(max_gas), found: header.gas_limit().clone() })));
158158
}
159159
Ok(())

ethcore/src/ethereum/ethash.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ impl Engine for Ethash {
131131
};
132132
header.set_difficulty(difficulty);
133133
header.set_gas_limit(gas_limit);
134-
if header.number().clone() >= self.ethash_params.dao_hardfork_transition &&
135-
header.number().clone() <= self.ethash_params.dao_hardfork_transition + 9 {
134+
if header.number() >= self.ethash_params.dao_hardfork_transition &&
135+
header.number() <= self.ethash_params.dao_hardfork_transition + 9 {
136136
header.set_extra_data(b"dao-hard-fork"[..].to_owned());
137137
}
138138
header.note_dirty();
@@ -183,7 +183,7 @@ impl Engine for Ethash {
183183

184184
// TODO: consider removing these lines.
185185
let min_difficulty = self.ethash_params.minimum_difficulty;
186-
if header.difficulty().clone() < min_difficulty {
186+
if header.difficulty() < &min_difficulty {
187187
return Err(From::from(BlockError::DifficultyOutOfBounds(OutOfBounds { min: Some(min_difficulty), max: None, found: header.difficulty().clone() })))
188188
}
189189

@@ -192,7 +192,7 @@ impl Engine for Ethash {
192192
header.nonce().low_u64(),
193193
&Ethash::to_ethash(header.mix_hash())
194194
)));
195-
if difficulty < header.difficulty().clone() {
195+
if &difficulty < header.difficulty() {
196196
return Err(From::from(BlockError::InvalidProofOfWork(OutOfBounds { min: Some(header.difficulty().clone()), max: None, found: difficulty })));
197197
}
198198

@@ -202,7 +202,7 @@ impl Engine for Ethash {
202202
return Err(From::from(BlockError::ExtraDataOutOfBounds(OutOfBounds { min: None, max: None, found: 0 })));
203203
}
204204

205-
if header.gas_limit().clone() > 0x7fffffffffffffffu64.into() {
205+
if header.gas_limit() > &0x7fffffffffffffffu64.into() {
206206
return Err(From::from(BlockError::InvalidGasLimit(OutOfBounds { min: None, max: Some(0x7fffffffffffffffu64.into()), found: header.gas_limit().clone() })));
207207
}
208208

@@ -218,10 +218,10 @@ impl Engine for Ethash {
218218
let result = self.pow.compute_light(header.number() as u64, &Ethash::to_ethash(header.bare_hash()), header.nonce().low_u64());
219219
let mix = Ethash::from_ethash(result.mix_hash);
220220
let difficulty = Ethash::boundary_to_difficulty(&Ethash::from_ethash(result.value));
221-
if mix != header.mix_hash().clone() {
221+
if mix != header.mix_hash() {
222222
return Err(From::from(BlockError::MismatchedH256SealElement(Mismatch { expected: mix, found: header.mix_hash() })));
223223
}
224-
if difficulty < header.difficulty().clone() {
224+
if &difficulty < header.difficulty() {
225225
return Err(From::from(BlockError::InvalidProofOfWork(OutOfBounds { min: Some(header.difficulty().clone()), max: None, found: difficulty })));
226226
}
227227
Ok(())
@@ -235,13 +235,13 @@ impl Engine for Ethash {
235235

236236
// Check difficulty is correct given the two timestamps.
237237
let expected_difficulty = self.calculate_difficulty(header, parent);
238-
if header.difficulty().clone() != expected_difficulty {
238+
if header.difficulty() != &expected_difficulty {
239239
return Err(From::from(BlockError::InvalidDifficulty(Mismatch { expected: expected_difficulty, found: header.difficulty().clone() })))
240240
}
241241
let gas_limit_divisor = self.ethash_params.gas_limit_bound_divisor;
242242
let min_gas = parent.gas_limit().clone() - parent.gas_limit().clone() / gas_limit_divisor;
243243
let max_gas = parent.gas_limit().clone() + parent.gas_limit().clone() / gas_limit_divisor;
244-
if header.gas_limit().clone() <= min_gas || header.gas_limit().clone() >= max_gas {
244+
if header.gas_limit() <= &min_gas || header.gas_limit() >= &max_gas {
245245
return Err(From::from(BlockError::InvalidGasLimit(OutOfBounds { min: Some(min_gas), max: Some(max_gas), found: header.gas_limit().clone() })));
246246
}
247247
Ok(())

0 commit comments

Comments
 (0)