Skip to content

Commit 1d2204f

Browse files
committed
Revert "use min_by"
This reverts commit 33042f4.
1 parent 33042f4 commit 1d2204f

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

modules/messages/src/lib.rs

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

332332
// compute actual dispatch weight that depends on the stored message size
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-
);
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+
};
338343

339344
Ok(PostDispatchInfo { actual_weight: Some(actual_weight), pays_fee: Pays::Yes })
340345
}
@@ -454,10 +459,11 @@ pub mod pallet {
454459
ReceivalResult::TooManyUnconfirmedMessages => (dispatch_weight, true),
455460
};
456461

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-
});
462+
let unspent_weight = if unspent_weight.ref_time() < dispatch_weight.ref_time() {
463+
unspent_weight
464+
} else {
465+
dispatch_weight
466+
};
461467
dispatch_weight_left -= dispatch_weight - unspent_weight;
462468
actual_weight = actual_weight.saturating_sub(unspent_weight).saturating_sub(
463469
// delivery call weight formula assumes that the fee is paid at

0 commit comments

Comments
 (0)