Skip to content

Commit 33042f4

Browse files
committed
use min_by
1 parent a7a3d3d commit 33042f4

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

modules/messages/src/lib.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -330,16 +330,11 @@ pub mod pallet {
330330
});
331331

332332
// compute actual dispatch weight that depends on the stored message size
333-
let maximal_increase_message_fee = T::WeightInfo::maximal_increase_message_fee();
334-
let current_increase_message_fee =
335-
T::WeightInfo::increase_message_fee(message_size as _);
336-
let actual_weight = if maximal_increase_message_fee.ref_time() <
337-
current_increase_message_fee.ref_time()
338-
{
339-
maximal_increase_message_fee
340-
} else {
341-
current_increase_message_fee
342-
};
333+
let actual_weight = sp_std::cmp::min_by(
334+
T::WeightInfo::maximal_increase_message_fee(),
335+
T::WeightInfo::increase_message_fee(message_size as _),
336+
|w1, w2| w1.ref_time().cmp(&w2.ref_time()),
337+
);
343338

344339
Ok(PostDispatchInfo { actual_weight: Some(actual_weight), pays_fee: Pays::Yes })
345340
}
@@ -459,11 +454,10 @@ pub mod pallet {
459454
ReceivalResult::TooManyUnconfirmedMessages => (dispatch_weight, true),
460455
};
461456

462-
let unspent_weight = if unspent_weight.ref_time() < dispatch_weight.ref_time() {
463-
unspent_weight
464-
} else {
465-
dispatch_weight
466-
};
457+
let unspent_weight =
458+
sp_std::cmp::min_by(unspent_weight, dispatch_weight, |w1, w2| {
459+
w1.ref_time().cmp(&w2.ref_time())
460+
});
467461
dispatch_weight_left -= dispatch_weight - unspent_weight;
468462
actual_weight = actual_weight.saturating_sub(unspent_weight).saturating_sub(
469463
// delivery call weight formula assumes that the fee is paid at

0 commit comments

Comments
 (0)