1- use pinocchio:: program_error:: ProgramError ;
1+ use pinocchio:: {
2+ hint:: { likely, unlikely} ,
3+ program_error:: ProgramError ,
4+ } ;
25
36pub mod account;
47pub mod account_state;
@@ -37,7 +40,7 @@ pub trait Initializable {
3740pub unsafe fn load < T : Initializable + Transmutable > ( bytes : & [ u8 ] ) -> Result < & T , ProgramError > {
3841 load_unchecked ( bytes) . and_then ( |t : & T | {
3942 // checks if the data is initialized
40- if t. is_initialized ( ) ? {
43+ if likely ( t. is_initialized ( ) ?) {
4144 Ok ( t)
4245 } else {
4346 Err ( ProgramError :: UninitializedAccount )
@@ -54,7 +57,7 @@ pub unsafe fn load<T: Initializable + Transmutable>(bytes: &[u8]) -> Result<&T,
5457/// The caller must ensure that `bytes` contains a valid representation of `T`.
5558#[ inline( always) ]
5659pub unsafe fn load_unchecked < T : Transmutable > ( bytes : & [ u8 ] ) -> Result < & T , ProgramError > {
57- if bytes. len ( ) != T :: LEN {
60+ if unlikely ( bytes. len ( ) != T :: LEN ) {
5861 return Err ( ProgramError :: InvalidAccountData ) ;
5962 }
6063 Ok ( & * ( bytes. as_ptr ( ) as * const T ) )
@@ -71,7 +74,7 @@ pub unsafe fn load_mut<T: Initializable + Transmutable>(
7174) -> Result < & mut T , ProgramError > {
7275 load_mut_unchecked ( bytes) . and_then ( |t : & mut T | {
7376 // checks if the data is initialized
74- if t. is_initialized ( ) ? {
77+ if likely ( t. is_initialized ( ) ?) {
7578 Ok ( t)
7679 } else {
7780 Err ( ProgramError :: UninitializedAccount )
@@ -90,7 +93,7 @@ pub unsafe fn load_mut<T: Initializable + Transmutable>(
9093pub unsafe fn load_mut_unchecked < T : Transmutable > (
9194 bytes : & mut [ u8 ] ,
9295) -> Result < & mut T , ProgramError > {
93- if bytes. len ( ) != T :: LEN {
96+ if unlikely ( bytes. len ( ) != T :: LEN ) {
9497 return Err ( ProgramError :: InvalidAccountData ) ;
9598 }
9699 Ok ( & mut * ( bytes. as_mut_ptr ( ) as * mut T ) )
0 commit comments