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 19, 2024
1 parent e987d2b commit 5ff00f9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 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.bytes().clone();
Self {
instruction_pointer: bytecode.as_ptr(),
bytecode,
Expand Down
8 changes: 4 additions & 4 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 bytes(&self) -> &Bytes {
match self {
Self::LegacyRaw(bytes) => bytes.clone(),
Self::LegacyRaw(bytes) => bytes,
Self::LegacyAnalyzed(analyzed) => analyzed.bytes(),
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
4 changes: 2 additions & 2 deletions crates/primitives/src/bytecode/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ impl LegacyAnalyzedBytecode {
/// Returns bytes of bytecode.
///
/// Bytes are padded with 32 zero bytes.
pub fn bytes(&self) -> Bytes {
self.bytecode.clone()
pub fn bytes(&self) -> &Bytes {
&self.bytecode
}

/// Original bytes length.
Expand Down

0 comments on commit 5ff00f9

Please sign in to comment.