Skip to content

Commit 03def88

Browse files
committed
f - use fewer operations
1 parent 6e514a2 commit 03def88

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

lightning/src/routing/scoring.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,14 +1163,11 @@ impl<L: Deref<Target = u64>, BRT: Deref<Target = HistoricalBucketRangeTracker>,
11631163
// half life has passed, approximate an additional three-quarter life by summing
11641164
// the results of taking both the *next two* half lives instead. This helps
11651165
// smooth out the decay.
1166+
let decayed_offset_msat = offset_msat.checked_shr(decays as u32).unwrap_or(0);
11661167
if half_decays % 2 == 0 {
1167-
offset_msat.checked_shr(decays as u32).unwrap_or(0)
1168+
decayed_offset_msat
11681169
} else {
1169-
offset_msat
1170-
.checked_shr((decays + 1) as u32)
1171-
.map(|decayed_offset_msat| decayed_offset_msat
1172-
+ offset_msat.checked_shr((decays + 2) as u32).unwrap_or(0))
1173-
.unwrap_or(0)
1170+
(decayed_offset_msat >> 1) + (decayed_offset_msat >> 2)
11741171
}
11751172
}
11761173
},

0 commit comments

Comments
 (0)