Simplify closures in call to fold

Remove unnecessary code comments and make the closure variable names more
terse with no loss of clarity.

Refactor only, no logic changes.
This commit is contained in:
Tobin C. Harding 2024-12-12 11:47:43 +11:00
parent aeca93b561
commit f42f13cd8d
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 10 additions and 19 deletions

View File

@ -851,29 +851,20 @@ where
I: IntoIterator<Item = InputWeightPrediction>, I: IntoIterator<Item = InputWeightPrediction>,
O: IntoIterator<Item = usize>, O: IntoIterator<Item = usize>,
{ {
// sum input_weights, input_count and count of inputs with witness data let (input_count, input_weight, inputs_with_witnesses) =
let (input_count, input_weight, inputs_with_witnesses) = inputs.into_iter().fold( inputs.into_iter().fold((0, 0, 0), |(count, weight, with_witnesses), prediction| {
(0, 0, 0),
|(count, input_weight, inputs_with_witnesses), prediction| {
( (
count + 1, count + 1,
input_weight + prediction.total_weight().to_wu() as usize, weight + prediction.total_weight().to_wu() as usize,
inputs_with_witnesses + (prediction.witness_size > 0) as usize, with_witnesses + (prediction.witness_size > 0) as usize,
) )
}, });
);
let (output_count, output_scripts_size) =
output_script_lens.into_iter().fold((0, 0), |(count, scripts_size), script_len| {
(count + 1, scripts_size + script_len + compact_size::encoded_size(script_len))
});
// This fold() does two things:
// 1) Counts the outputs and returns the sum as `output_count`.
// 2) Sums the output script sizes and returns the sum as `output_scripts_size`.
// script_len + the length of a VarInt struct that stores the value of script_len
let (output_count, output_scripts_size) = output_script_lens.into_iter().fold(
(0, 0),
|(output_count, total_scripts_size), script_len| {
let script_size = script_len + compact_size::encoded_size(script_len);
(output_count + 1, total_scripts_size + script_size)
},
);
predict_weight_internal( predict_weight_internal(
input_count, input_count,
input_weight, input_weight,