Skip to content

Commit 79b2659

Browse files
committed
Change from arc.clone() to Arc::clone()
I think it is better to be explicit with Arc::clone to clearly highlight that this is cheap clone
1 parent bb63808 commit 79b2659

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/descriptor/tr.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ impl<Pk: MiniscriptKey> Clone for Tr<Pk> {
6060
Self {
6161
internal_key: self.internal_key.clone(),
6262
tree: self.tree.clone(),
63-
spend_info: Mutex::new(self.spend_info.lock().expect("Lock poisoned").clone()),
63+
spend_info: Mutex::new(
64+
self.spend_info
65+
.lock()
66+
.expect("Lock poisoned")
67+
.as_ref()
68+
.map(Arc::clone),
69+
),
6470
}
6571
}
6672
}
@@ -216,7 +222,7 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
216222
// read only panics if the lock is poisoned (meaning other thread having a lock panicked)
217223
let read_lock = self.spend_info.lock().expect("Lock poisoned");
218224
if let Some(ref spend_info) = *read_lock {
219-
return spend_info.clone();
225+
return Arc::clone(spend_info);
220226
}
221227
drop(read_lock);
222228

@@ -260,7 +266,7 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
260266
}
261267
};
262268
let spend_info = Arc::new(data);
263-
*self.spend_info.lock().expect("Lock poisoned") = Some(spend_info.clone());
269+
*self.spend_info.lock().expect("Lock poisoned") = Some(Arc::clone(&spend_info));
264270
spend_info
265271
}
266272
}

0 commit comments

Comments
 (0)