Skip to content

Commit 405f6e0

Browse files
committed
Write Weight bytes directly to buffer
1 parent 9ef140b commit 405f6e0

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

crates/env/src/engine/on_chain/pallet_revive.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ fn solidity_encode_bytes(
272272
///
273273
/// # Developer Note
274274
///
275-
// The implementation does not use `.div_ceil()`, as that function is more complex
276-
// and would use up more stack space.
275+
/// The implementation does not use `.div_ceil()`, as that function is more complex
276+
/// and would use up more stack space.
277277
#[allow(clippy::manual_div_ceil)]
278278
#[inline(always)]
279279
const fn solidity_padded_len(len: usize) -> usize {
@@ -1382,11 +1382,12 @@ impl TypedEnvBackend for EnvInstance {
13821382
// 96 because 64 for `Weight` and 32 for `bytes` offset
13831383
let n = solidity_encode_bytes(enc_msg, 96, 0, &mut buffer[4..]);
13841384

1385-
let mut weight_bytes = [0u8; 64];
1386-
weight_bytes[24..32].copy_from_slice(&weight.ref_time().to_be_bytes());
1387-
weight_bytes[56..64].copy_from_slice(&weight.proof_size().to_be_bytes());
13881385
// put the `Weight` after the `bytes` offset word
1389-
buffer[4 + 32..4 + 32 + 64].copy_from_slice(&weight_bytes[..]);
1386+
// 4 bytes for the selector + 32 bytes for the `bytes` offset word
1387+
buffer[4 + 32 + 24..4 + 32 + 32]
1388+
.copy_from_slice(&weight.ref_time().to_be_bytes()[..]);
1389+
buffer[4 + 32 + 32 + 24..4 + 32 + 32 + 32]
1390+
.copy_from_slice(&weight.proof_size().to_be_bytes()[..]);
13901391

13911392
let _call_result = ext::call(
13921393
CallFlags::empty(),

0 commit comments

Comments
 (0)