Skip to content

Commit 4cb7bc6

Browse files
authored
chore: use Bytes::clone where possible (#11160)
1 parent c799853 commit 4cb7bc6

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

crates/cheatcodes/src/evm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
};
88
use alloy_consensus::TxEnvelope;
99
use alloy_genesis::{Genesis, GenesisAccount};
10-
use alloy_primitives::{Address, B256, Bytes, U256, map::HashMap};
10+
use alloy_primitives::{Address, B256, U256, map::HashMap};
1111
use alloy_rlp::Decodable;
1212
use alloy_sol_types::SolValue;
1313
use foundry_common::fs::{read_json_file, write_json_file};
@@ -532,7 +532,7 @@ impl Cheatcode for etchCall {
532532
let Self { target, newRuntimeBytecode } = self;
533533
ensure_not_precompile!(target, ccx);
534534
ccx.ecx.journaled_state.load_account(*target)?;
535-
let bytecode = Bytecode::new_raw_checked(Bytes::copy_from_slice(newRuntimeBytecode))
535+
let bytecode = Bytecode::new_raw_checked(newRuntimeBytecode.clone())
536536
.map_err(|e| fmt_err!("failed to create bytecode: {e}"))?;
537537
ccx.ecx.journaled_state.set_code(*target, bytecode);
538538
Ok(Default::default())

crates/cheatcodes/src/evm/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ fn mock_calls(
200200
ret_type: InstructionResult,
201201
) {
202202
state.mocked_calls.entry(*callee).or_default().insert(
203-
MockCallDataContext { calldata: Bytes::copy_from_slice(cdata), value: value.copied() },
203+
MockCallDataContext { calldata: cdata.clone(), value: value.copied() },
204204
rdata_vec
205205
.iter()
206206
.map(|rdata| MockCallReturnData { ret_type, data: rdata.clone() })

crates/common/src/transactions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use alloy_consensus::{Transaction, TxEnvelope, transaction::SignerRecoverable};
44
use alloy_eips::eip7702::SignedAuthorization;
55
use alloy_network::AnyTransactionReceipt;
6-
use alloy_primitives::{Address, TxKind, U256};
6+
use alloy_primitives::{Address, Bytes, TxKind, U256};
77
use alloy_provider::{
88
Provider,
99
network::{AnyNetwork, ReceiptResponse, TransactionBuilder},
@@ -221,10 +221,10 @@ impl TransactionMaybeSigned {
221221
}
222222
}
223223

224-
pub fn input(&self) -> Option<&[u8]> {
224+
pub fn input(&self) -> Option<&Bytes> {
225225
match self {
226226
Self::Signed { tx, .. } => Some(tx.input()),
227-
Self::Unsigned(tx) => tx.input.input().map(|i| i.as_ref()),
227+
Self::Unsigned(tx) => tx.input.input(),
228228
}
229229
}
230230

crates/evm/core/src/evm.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,9 @@ impl<'db, I: InspectorExt> FoundryHandler<'db, I> {
323323
return Ok(Some(FrameResult::Call(CallOutcome {
324324
result: InterpreterResult {
325325
result: InstructionResult::Revert,
326-
output: Bytes::copy_from_slice(
327-
format!("missing CREATE2 deployer: {create2_deployer}").as_bytes(),
326+
output: Bytes::from(
327+
format!("missing CREATE2 deployer: {create2_deployer}")
328+
.into_bytes(),
328329
),
329330
gas: Gas::new(gas_limit),
330331
},

crates/script/src/simulate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
};
1212
use alloy_chains::NamedChain;
1313
use alloy_network::TransactionBuilder;
14-
use alloy_primitives::{Address, Bytes, TxKind, U256, map::HashMap, utils::format_units};
14+
use alloy_primitives::{Address, TxKind, U256, map::HashMap, utils::format_units};
1515
use dialoguer::Confirm;
1616
use eyre::{Context, Result};
1717
use forge_script_sequence::{ScriptSequence, TransactionWithMetadata};
@@ -127,7 +127,7 @@ impl PreSimulationState {
127127
tx.from()
128128
.expect("transaction doesn't have a `from` address at execution time"),
129129
to,
130-
tx.input().map(Bytes::copy_from_slice),
130+
tx.input().cloned(),
131131
tx.value(),
132132
tx.authorization_list(),
133133
)

0 commit comments

Comments
 (0)