@@ -214,27 +214,22 @@ fn get_branch_requirements_dependencies(
214214/// Rectify (see [CostTypeTrait::rectify]) is needed in case the branch cost is negative
215215/// (e.g., in `coupon_refund`).
216216fn get_branch_requirements <
217+ ' a ,
217218 CostType : CostTypeTrait ,
218219 SpecificCostContext : SpecificCostContextTrait < CostType > ,
219220> (
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 ] ,
225226 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+ } )
238233}
239234
240235/// For every `branch_align`, `withdraw_gas`, `redeposit_gas` and `coupon_refund` statements,
@@ -257,9 +252,10 @@ fn analyze_gas_statements<
257252 return Ok ( ( ) ) ;
258253 } ;
259254 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 (
261257 specific_context,
262- & |statement_idx| context . wallet_at ( statement_idx ) ,
258+ wallet_at_fn ,
263259 idx,
264260 invocation,
265261 libfunc_cost,
@@ -269,7 +265,7 @@ fn analyze_gas_statements<
269265 let wallet_value = context. wallet_at ( idx) . value ;
270266
271267 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)
273269 {
274270 if let BranchCost :: WithdrawGas ( WithdrawGasBranchInfo { success : true , .. } ) = branch_cost {
275271 // Note that `idx.next(&branch_info.target)` is indeed branch align due to
@@ -359,12 +355,11 @@ impl<CostType: CostTypeTrait> WalletInfo<CostType> {
359355 /// `target_value` is the target value for this statement. See [CostContext::target_values].
360356 fn merge (
361357 branch_costs : & [ BranchCost ] ,
362- branches : Vec < Self > ,
358+ branches : impl ExactSizeIterator < Item = Self > ,
363359 target_value : Option < & CostType > ,
364360 ) -> Self {
365361 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 ) ) ;
368363
369364 // If there are multiple branches, there must be a branch_align in each of them, which
370365 // can be used to increase the wallet value up to the target value.
@@ -490,9 +485,10 @@ impl<CostType: CostTypeTrait> CostContext<'_, CostType> {
490485 let libfunc_cost = & self . branch_costs [ idx. 0 ] ;
491486
492487 // 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 (
494490 specific_cost_context,
495- & |statement_idx| self . wallet_at ( statement_idx ) ,
491+ wallet_at_fn ,
496492 idx,
497493 invocation,
498494 libfunc_cost,
@@ -601,9 +597,10 @@ impl<CostType: CostTypeTrait> CostContext<'_, CostType> {
601597
602598 let libfunc_cost = & self . branch_costs [ idx. 0 ] ;
603599
600+ let wallet_at_fn = & |statement_idx : & StatementIdx | self . wallet_at ( statement_idx) ;
604601 let branch_requirements = get_branch_requirements (
605602 specific_cost_context,
606- & |statement_idx| self . wallet_at ( statement_idx ) ,
603+ wallet_at_fn ,
607604 idx,
608605 invocation,
609606 libfunc_cost,
0 commit comments