@@ -214,27 +214,22 @@ fn get_branch_requirements_dependencies(
214
214
/// Rectify (see [CostTypeTrait::rectify]) is needed in case the branch cost is negative
215
215
/// (e.g., in `coupon_refund`).
216
216
fn get_branch_requirements <
217
+ ' a ,
217
218
CostType : CostTypeTrait ,
218
219
SpecificCostContext : SpecificCostContextTrait < CostType > ,
219
220
> (
220
- specific_context : & SpecificCostContext ,
221
- wallet_at_fn : & impl Fn ( & StatementIdx ) -> WalletInfo < CostType > ,
222
- idx : & StatementIdx ,
223
- invocation : & Invocation ,
224
- libfunc_cost : & [ BranchCost ] ,
221
+ specific_context : & ' a SpecificCostContext ,
222
+ wallet_at_fn : & ' a impl Fn ( & StatementIdx ) -> WalletInfo < CostType > ,
223
+ idx : & ' a StatementIdx ,
224
+ invocation : & ' a Invocation ,
225
+ libfunc_cost : & ' a [ BranchCost ] ,
225
226
rectify : bool ,
226
- ) -> Vec < WalletInfo < CostType > > {
227
- zip_eq ( & invocation. branches , libfunc_cost)
228
- . map ( |( branch_info, branch_cost) | {
229
- let res = specific_context. get_branch_requirement (
230
- wallet_at_fn,
231
- idx,
232
- branch_info,
233
- branch_cost,
234
- ) ;
235
- if rectify { res. rectify ( ) } else { res }
236
- } )
237
- . collect ( )
227
+ ) -> impl ExactSizeIterator < Item = WalletInfo < CostType > > + ' a {
228
+ zip_eq ( & invocation. branches , libfunc_cost) . map ( move |( branch_info, branch_cost) | {
229
+ let res =
230
+ specific_context. get_branch_requirement ( wallet_at_fn, idx, branch_info, branch_cost) ;
231
+ if rectify { res. rectify ( ) } else { res }
232
+ } )
238
233
}
239
234
240
235
/// For every `branch_align`, `withdraw_gas`, `redeposit_gas` and `coupon_refund` statements,
@@ -257,9 +252,10 @@ fn analyze_gas_statements<
257
252
return Ok ( ( ) ) ;
258
253
} ;
259
254
let libfunc_cost = & context. branch_costs [ idx. 0 ] ;
260
- let branch_requirements: Vec < WalletInfo < CostType > > = get_branch_requirements (
255
+ let wallet_at_fn = & |statement_idx : & StatementIdx | context. wallet_at ( statement_idx) ;
256
+ let branch_requirements = get_branch_requirements (
261
257
specific_context,
262
- & |statement_idx| context . wallet_at ( statement_idx ) ,
258
+ wallet_at_fn ,
263
259
idx,
264
260
invocation,
265
261
libfunc_cost,
@@ -269,7 +265,7 @@ fn analyze_gas_statements<
269
265
let wallet_value = context. wallet_at ( idx) . value ;
270
266
271
267
for ( branch_info, branch_cost, branch_requirement) in
272
- zip_eq3 ( & invocation. branches , libfunc_cost, & branch_requirements)
268
+ zip_eq3 ( & invocation. branches , libfunc_cost, branch_requirements)
273
269
{
274
270
if let BranchCost :: WithdrawGas ( WithdrawGasBranchInfo { success : true , .. } ) = branch_cost {
275
271
// Note that `idx.next(&branch_info.target)` is indeed branch align due to
@@ -359,12 +355,11 @@ impl<CostType: CostTypeTrait> WalletInfo<CostType> {
359
355
/// `target_value` is the target value for this statement. See [CostContext::target_values].
360
356
fn merge (
361
357
branch_costs : & [ BranchCost ] ,
362
- branches : Vec < Self > ,
358
+ branches : impl ExactSizeIterator < Item = Self > ,
363
359
target_value : Option < & CostType > ,
364
360
) -> Self {
365
361
let n_branches = branches. len ( ) ;
366
- let mut max_value =
367
- CostType :: max ( branches. iter ( ) . map ( |wallet_info| wallet_info. value . clone ( ) ) ) ;
362
+ let mut max_value = CostType :: max ( branches. map ( |wallet_info| wallet_info. value ) ) ;
368
363
369
364
// If there are multiple branches, there must be a branch_align in each of them, which
370
365
// can be used to increase the wallet value up to the target value.
@@ -490,9 +485,10 @@ impl<CostType: CostTypeTrait> CostContext<'_, CostType> {
490
485
let libfunc_cost = & self . branch_costs [ idx. 0 ] ;
491
486
492
487
// For each branch, compute the required value for the wallet.
493
- let branch_requirements: Vec < WalletInfo < CostType > > = get_branch_requirements (
488
+ let wallet_at_fn = & |statement_idx : & StatementIdx | self . wallet_at ( statement_idx) ;
489
+ let branch_requirements = get_branch_requirements (
494
490
specific_cost_context,
495
- & |statement_idx| self . wallet_at ( statement_idx ) ,
491
+ wallet_at_fn ,
496
492
idx,
497
493
invocation,
498
494
libfunc_cost,
@@ -601,9 +597,10 @@ impl<CostType: CostTypeTrait> CostContext<'_, CostType> {
601
597
602
598
let libfunc_cost = & self . branch_costs [ idx. 0 ] ;
603
599
600
+ let wallet_at_fn = & |statement_idx : & StatementIdx | self . wallet_at ( statement_idx) ;
604
601
let branch_requirements = get_branch_requirements (
605
602
specific_cost_context,
606
- & |statement_idx| self . wallet_at ( statement_idx ) ,
603
+ wallet_at_fn ,
607
604
idx,
608
605
invocation,
609
606
libfunc_cost,
0 commit comments