Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 29 additions & 24 deletions sdk/pinocchio/src/entrypoint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use core::{

use crate::{
account_info::{Account, AccountInfo, MAX_PERMITTED_DATA_INCREASE},
hint::unlikely,
pubkey::Pubkey,
BPF_ALIGN_OF_U128, MAX_TX_ACCOUNTS, NON_DUP_MARKER,
};
Expand Down Expand Up @@ -353,31 +354,35 @@ pub unsafe fn deserialize<const MAX_ACCOUNTS: usize>(
// This is an optimization to reduce the number of jumps required to process the
// accounts. The macro `process_accounts` will generate inline code to process the
// specified number of accounts.
while to_process_plus_one > 5 {
// Process 5 accounts at a time.
process_accounts!(5 => (input, accounts, accounts_slice));
to_process_plus_one -= 5;
}

// There might be remaining accounts to process.
match to_process_plus_one {
5 => {
process_accounts!(4 => (input, accounts, accounts_slice));
}
4 => {
process_accounts!(3 => (input, accounts, accounts_slice));
}
3 => {
process_accounts!(2 => (input, accounts, accounts_slice));
}
2 => {
process_accounts!(1 => (input, accounts, accounts_slice));
if unlikely(to_process_plus_one == 2) {
process_accounts!(1 => (input, accounts, accounts_slice));
} else {
while to_process_plus_one > 5 {
// Process 5 accounts at a time.
process_accounts!(5 => (input, accounts, accounts_slice));
to_process_plus_one -= 5;
}
1 => (),
_ => {
// SAFETY: `while` loop above makes sure that `to_process_plus_one`
// has 1 to 5 entries left.
unsafe { core::hint::unreachable_unchecked() }

// There might be remaining accounts to process.
match to_process_plus_one {
5 => {
process_accounts!(4 => (input, accounts, accounts_slice));
}
4 => {
process_accounts!(3 => (input, accounts, accounts_slice));
}
3 => {
process_accounts!(2 => (input, accounts, accounts_slice));
}
2 => {
process_accounts!(1 => (input, accounts, accounts_slice));
}
1 => (),
_ => {
// SAFETY: `while` loop above makes sure that `to_process_plus_one`
// has 1 to 5 entries left.
unsafe { core::hint::unreachable_unchecked() }
}
}
}

Expand Down