From: Matt Corallo Date: Sun, 19 Apr 2020 05:16:20 +0000 (-0400) Subject: Avoid a few useless clone() calls in onchaintx.rs X-Git-Tag: v0.0.12~78^2~4 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=ddda194d5324f1e9ef0da3d14fd40f1f38c10075;p=rust-lightning Avoid a few useless clone() calls in onchaintx.rs 3d640da5c343111f538f006996c13c9a98e0d9e6 looped over a new HashMap new_claims, clone()ing entries out of it right before droppng the whole thing. This is an obvious candidate for drain(..). --- diff --git a/lightning/src/ln/onchaintx.rs b/lightning/src/ln/onchaintx.rs index 3b8238ddc..102a688df 100644 --- a/lightning/src/ln/onchaintx.rs +++ b/lightning/src/ln/onchaintx.rs @@ -585,17 +585,17 @@ impl OnchainTxHandler { // Generate claim transactions and track them to bump if necessary at // height timer expiration (i.e in how many blocks we're going to take action). - for claim in new_claims { - let mut claim_material = ClaimTxBumpMaterial { height_timer: None, feerate_previous: 0, soonest_timelock: claim.0, per_input_material: claim.1.clone() }; + for (soonest_timelock, claim) in new_claims.drain(..) { + let mut claim_material = ClaimTxBumpMaterial { height_timer: None, feerate_previous: 0, soonest_timelock, per_input_material: claim }; if let Some((new_timer, new_feerate, tx)) = self.generate_claim_tx(height, &claim_material, &*fee_estimator) { claim_material.height_timer = new_timer; claim_material.feerate_previous = new_feerate; let txid = tx.txid(); - self.pending_claim_requests.insert(txid, claim_material); - for k in claim.1.keys() { + for k in claim_material.per_input_material.keys() { log_trace!(self, "Registering claiming request for {}:{}", k.txid, k.vout); self.claimable_outpoints.insert(k.clone(), (txid, height)); } + self.pending_claim_requests.insert(txid, claim_material); log_trace!(self, "Broadcast onchain {}", log_tx!(tx)); broadcaster.broadcast_transaction(&tx); }