Skip to content

Commit

Permalink
f Avoid superfluous collect
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed Feb 2, 2024
1 parent 735b89f commit 6c73829
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions lightning/src/util/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,22 +318,18 @@ where
&self, mut output_descriptors: Vec<SpendableOutputDescriptor>,
channel_id: Option<ChannelId>, exclude_static_ouputs: bool,
) {
let relevant_descriptors = if exclude_static_ouputs {
output_descriptors
.drain(..)
.filter(|desc| !matches!(desc, SpendableOutputDescriptor::StaticOutput { .. }))
.collect::<Vec<_>>()
} else {
output_descriptors
};

if relevant_descriptors.is_empty() {
return;
}

let relevant_descriptors = output_descriptors
.drain(..)
.filter(|desc| {
!(exclude_static_ouputs &&
matches!(desc, SpendableOutputDescriptor::StaticOutput { .. }))
});

let mut processed_outputs = false;
{
let mut locked_outputs = self.outputs.lock().unwrap();
for descriptor in relevant_descriptors {
processed_outputs = true;
let id = self.entropy_source.get_secure_random_bytes();
let output_info = TrackedSpendableOutput {
id,
Expand All @@ -353,7 +349,9 @@ where
}
}

self.rebroadcast_if_necessary();
if processed_outputs {
self.rebroadcast_if_necessary();
}
}

/// Returns a list of the currently tracked spendable outputs.
Expand Down

0 comments on commit 6c73829

Please sign in to comment.