DRY redundant calls to `$candidate.htlc_minimum_msat()` in routing
authorMatt Corallo <git@bluematt.me>
Fri, 8 Dec 2023 01:49:08 +0000 (01:49 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 20 Mar 2024 00:51:20 +0000 (00:51 +0000)
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

index d2c32f73cf6a391c3b476de6daef2fdfb4b7a8d9..14837018a169c5270eb76f26de4c611a59bdbd15 100644 (file)
@@ -2255,14 +2255,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));