Skip to content

Commit

Permalink
chore: don't clone bytes in Bytecode::bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Apr 21, 2024
1 parent e987d2b commit 02d7952
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion crates/interpreter/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Interpreter {
panic!("Contract is not execution ready {:?}", contract.bytecode);
}
let is_eof = contract.bytecode.is_eof();
let bytecode = contract.bytecode.bytecode_bytes();
let bytecode = contract.bytecode.bytecode().clone();
Self {
instruction_pointer: bytecode.as_ptr(),
bytecode,
Expand Down
10 changes: 5 additions & 5 deletions crates/primitives/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ impl Bytecode {
}

/// Returns a reference to the bytecode.
///
/// In case of EOF this will be the first code section.
#[inline]
pub fn bytecode_bytes(&self) -> Bytes {
pub fn bytecode(&self) -> &Bytes {
match self {
Self::LegacyRaw(bytes) => bytes.clone(),
Self::LegacyAnalyzed(analyzed) => analyzed.bytes(),
Self::LegacyRaw(bytes) => bytes,
Self::LegacyAnalyzed(analyzed) => analyzed.bytecode(),
Self::Eof(eof) => eof
.body
.code(0)
.expect("Valid EOF has at least one code section")
.clone(),
.expect("Valid EOF has at least one code section"),
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/primitives/src/bytecode/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ impl LegacyAnalyzedBytecode {
}
}

/// Returns bytes of bytecode.
/// Returns a reference to the bytecode.
///
/// Bytes are padded with 32 zero bytes.
pub fn bytes(&self) -> Bytes {
self.bytecode.clone()
/// The bytecode is padded with 32 zero bytes.
pub fn bytecode(&self) -> &Bytes {
&self.bytecode
}

/// Original bytes length.
Expand Down

0 comments on commit 02d7952

Please sign in to comment.