@@ -32,7 +32,9 @@ pub struct ResolvedTransactionView<D: TransactionData> {
3232 /// The resolved address lookups.
3333 resolved_addresses : Option < LoadedAddresses > ,
3434 /// A cache for whether an address is writable.
35- writable_cache : Vec < bool > , // TODO: should this be a vec, bitset, or array[256].
35+ // Sanitized transactions are guaranteed to have a maximum of 256 keys,
36+ // because account indexing is done with a u8.
37+ writable_cache : [ bool ; 256 ] ,
3638}
3739
3840impl < D : TransactionData > Deref for ResolvedTransactionView < D > {
@@ -91,12 +93,12 @@ impl<D: TransactionData> ResolvedTransactionView<D> {
9193 view : & TransactionView < true , D > ,
9294 resolved_addresses : Option < & LoadedAddresses > ,
9395 reserved_account_keys : & HashSet < Pubkey > ,
94- ) -> Vec < bool > {
96+ ) -> [ bool ; 256 ] {
9597 // Build account keys so that we can iterate over and check if
9698 // an address is writable.
9799 let account_keys = AccountKeys :: new ( view. static_account_keys ( ) , resolved_addresses) ;
98100
99- let mut is_writable_cache = Vec :: with_capacity ( account_keys . len ( ) ) ;
101+ let mut is_writable_cache = [ false ; 256 ] ;
100102 let num_static_account_keys = usize:: from ( view. num_static_account_keys ( ) ) ;
101103 let num_writable_lookup_accounts = usize:: from ( view. total_writable_lookup_accounts ( ) ) ;
102104 let num_signed_accounts = usize:: from ( view. num_required_signatures ( ) ) ;
@@ -120,7 +122,7 @@ impl<D: TransactionData> ResolvedTransactionView<D> {
120122 } ;
121123
122124 // If the key is reserved it cannot be writable.
123- is_writable_cache. push ( is_requested_write && !reserved_account_keys. contains ( key) ) ;
125+ is_writable_cache[ index ] = is_requested_write && !reserved_account_keys. contains ( key) ;
124126 }
125127
126128 // If a program account is locked, it cannot be writable unless the
0 commit comments