From 3e902401e0f4e56d30c2b537ca53cf9392cea50c Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 8 Dec 2023 01:49:08 +0000 Subject: [PATCH] DRY redundant calls to `$candidate.htlc_minimum_msat()` in routing While LLVM should inline and elide the redundant calls, because the router is rather large LLVM can decide against inlining in some cases where it would be an nice win. Thus, its worth DRY'ing the redundant calls explicitly. --- lightning/src/routing/router.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 66b2d87e5..bbf73e531 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -2425,14 +2425,15 @@ where L::Target: Logger { // Can't overflow due to how the values were computed right above. None => unreachable!(), }; + let htlc_minimum_msat = $candidate.htlc_minimum_msat(); #[allow(unused_comparisons)] // $next_hops_path_htlc_minimum_msat is 0 in some calls so rustc complains - let over_path_minimum_msat = amount_to_transfer_over_msat >= $candidate.htlc_minimum_msat() && + let over_path_minimum_msat = amount_to_transfer_over_msat >= htlc_minimum_msat && amount_to_transfer_over_msat >= $next_hops_path_htlc_minimum_msat; #[allow(unused_comparisons)] // $next_hops_path_htlc_minimum_msat is 0 in some calls so rustc complains let may_overpay_to_meet_path_minimum_msat = - ((amount_to_transfer_over_msat < $candidate.htlc_minimum_msat() && - recommended_value_msat >= $candidate.htlc_minimum_msat()) || + ((amount_to_transfer_over_msat < htlc_minimum_msat && + recommended_value_msat >= htlc_minimum_msat) || (amount_to_transfer_over_msat < $next_hops_path_htlc_minimum_msat && recommended_value_msat >= $next_hops_path_htlc_minimum_msat)); -- 2.39.5