Skip to content

Commit d2bf84a

Browse files
afilinicsralvall
authored andcommitted
Avoid cloning vecs
1 parent ef1c7be commit d2bf84a

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/wallet/coin_selection.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@
4646
//! let mut selected_amount = 0;
4747
//! let mut additional_weight = 0;
4848
//! let all_utxos_selected = required_utxos
49-
//! .clone()
5049
//! .into_iter()
51-
//! .chain(optional_utxos.clone())
50+
//! .chain(optional_utxos.into_iter())
5251
//! .scan(
5352
//! (&mut selected_amount, &mut additional_weight),
5453
//! |(selected_amount, additional_weight), weighted_utxo| {
5554
//! **selected_amount += weighted_utxo.utxo.txout().value;
5655
//! **additional_weight += TXIN_BASE_WEIGHT + weighted_utxo.satisfaction_weight;
57-
//! Some(weighted_utxo.utxo)
56+
//! Some(weighted_utxo)
5857
//! },
5958
//! )
6059
//! .collect::<Vec<_>>();
@@ -69,10 +68,7 @@
6968
//!
7069
//! let calculated_waste = Some(
7170
//! calculate_waste(
72-
//! required_utxos
73-
//! .into_iter()
74-
//! .chain(optional_utxos)
75-
//! .collect::<Vec<WeightedUtxo>>(),
71+
//! &all_utxos_selected,
7672
//! None,
7773
//! amount_needed,
7874
//! fee_rate,
@@ -82,7 +78,7 @@
8278
//! );
8379
//!
8480
//! Ok(CoinSelectionResult::new(
85-
//! all_utxos_selected,
81+
//! all_utxos_selected.into_iter().map(|u| u.utxo).collect(),
8682
//! fee_amount + additional_fees,
8783
//! calculated_waste,
8884
//! ))
@@ -167,7 +163,7 @@ impl CoinSelectionResult {
167163

168164
pub fn get_waste(
169165
&self,
170-
selected: Vec<WeightedUtxo>,
166+
selected: &[WeightedUtxo],
171167
cost_of_change: Option<u64>,
172168
target: u64,
173169
fee_rate: FeeRate,
@@ -192,14 +188,14 @@ impl CoinSelectionResult {
192188
}
193189

194190
pub fn calculate_waste(
195-
selected: Vec<WeightedUtxo>,
191+
selected: &[WeightedUtxo],
196192
cost_of_change: Option<u64>,
197193
target: u64,
198194
fee_rate: FeeRate,
199195
long_term_fee_rate: FeeRate,
200196
) -> Result<Waste, Error> {
201197
// Always consider the cost of spending an input now vs in the future.
202-
let utxo_groups: Vec<OutputGroup> = selected
198+
let utxo_groups: Vec<_> = selected
203199
.iter()
204200
.map(|u| OutputGroup::new(u, fee_rate))
205201
.collect();

0 commit comments

Comments
 (0)