@@ -32,7 +32,9 @@ pub struct ResolvedTransactionView<D: TransactionData> {
32
32
/// The resolved address lookups.
33
33
resolved_addresses : Option < LoadedAddresses > ,
34
34
/// 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 ] ,
36
38
}
37
39
38
40
impl < D : TransactionData > Deref for ResolvedTransactionView < D > {
@@ -91,12 +93,12 @@ impl<D: TransactionData> ResolvedTransactionView<D> {
91
93
view : & TransactionView < true , D > ,
92
94
resolved_addresses : Option < & LoadedAddresses > ,
93
95
reserved_account_keys : & HashSet < Pubkey > ,
94
- ) -> Vec < bool > {
96
+ ) -> [ bool ; 256 ] {
95
97
// Build account keys so that we can iterate over and check if
96
98
// an address is writable.
97
99
let account_keys = AccountKeys :: new ( view. static_account_keys ( ) , resolved_addresses) ;
98
100
99
- let mut is_writable_cache = Vec :: with_capacity ( account_keys . len ( ) ) ;
101
+ let mut is_writable_cache = [ false ; 256 ] ;
100
102
let num_static_account_keys = usize:: from ( view. num_static_account_keys ( ) ) ;
101
103
let num_writable_lookup_accounts = usize:: from ( view. total_writable_lookup_accounts ( ) ) ;
102
104
let num_signed_accounts = usize:: from ( view. num_required_signatures ( ) ) ;
@@ -120,7 +122,7 @@ impl<D: TransactionData> ResolvedTransactionView<D> {
120
122
} ;
121
123
122
124
// 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) ;
124
126
}
125
127
126
128
// If a program account is locked, it cannot be writable unless the
0 commit comments