Skip to content

Commit 809ab3d

Browse files
committed
Use compiler hints from pinocchio
1 parent 5d2024c commit 809ab3d

File tree

4 files changed

+5
-38
lines changed

4 files changed

+5
-38
lines changed

p-interface/src/lib.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,3 @@ pub mod state;
88
pub mod program {
99
pinocchio_pubkey::declare_id!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
1010
}
11-
12-
/// A "dummy" function with a hint to the compiler that it is unlikely to be
13-
/// called.
14-
///
15-
/// This function is used as a hint to the compiler to optimize other code paths
16-
/// instead of the one where the function is used.
17-
#[cold]
18-
pub const fn cold_path() {}
19-
20-
/// Return the given `bool` value with a hint to the compiler that `true` is the
21-
/// likely case.
22-
#[inline(always)]
23-
pub const fn likely(b: bool) -> bool {
24-
if b {
25-
true
26-
} else {
27-
cold_path();
28-
false
29-
}
30-
}
31-
32-
/// Return a given `bool` value with a hint to the compiler that `false` is the
33-
/// likely case.
34-
#[inline(always)]
35-
pub const fn unlikely(b: bool) -> bool {
36-
if b {
37-
cold_path();
38-
true
39-
} else {
40-
false
41-
}
42-
}

p-interface/src/state/account.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use {
22
super::{account_state::AccountState, COption, Initializable, Transmutable},
3-
crate::likely,
4-
pinocchio::{program_error::ProgramError, pubkey::Pubkey},
3+
pinocchio::{hint::likely, program_error::ProgramError, pubkey::Pubkey},
54
};
65

76
/// Incinerator address.

p-token/src/processor/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use {
22
core::{slice::from_raw_parts, str::from_utf8_unchecked},
33
pinocchio::{
4-
account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey,
4+
account_info::AccountInfo, hint::unlikely, program_error::ProgramError, pubkey::Pubkey,
55
syscalls::sol_memcpy_, ProgramResult,
66
},
77
pinocchio_token_interface::{
@@ -12,7 +12,6 @@ use {
1212
multisig::{Multisig, MAX_SIGNERS},
1313
Transmutable,
1414
},
15-
unlikely,
1615
},
1716
};
1817

p-token/src/processor/shared/transfer.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use {
22
crate::processor::{check_account_owner, validate_owner},
3-
pinocchio::{account_info::AccountInfo, program_error::ProgramError, ProgramResult},
3+
pinocchio::{
4+
account_info::AccountInfo, hint::unlikely, program_error::ProgramError, ProgramResult,
5+
},
46
pinocchio_token_interface::{
57
error::TokenError,
68
state::{account::Account, load, load_mut, load_mut_unchecked, mint::Mint},
7-
unlikely,
89
},
910
};
1011

0 commit comments

Comments
 (0)