Skip to content

Commit d89db75

Browse files
committed
Replace Arc.clone() syntax with Arc::clone() in net-tokio
`arc.clone()` leaves the code somewhat ambiguous to whether we're doing an expensive deep-clone operation or if we're doing a (relatively) cheap pointer-copy-and-atomic-increment operation. More importantly, it leaves entirely unclear what the semantics of the object we just created are - does updating it update the original or leave it be? Thus, here, we replace `arc.clone()` calls with `Arc::clone()` in `lightning-net-tokio/src/lib.rs`
1 parent 217a5b0 commit d89db75

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lightning-net-tokio/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl Connection {
183183
// a chance to do some work.
184184
let mut buf = [0; 4096];
185185

186-
let mut our_descriptor = SocketDescriptor::new(us.clone());
186+
let mut our_descriptor = SocketDescriptor::new(Arc::clone(&us));
187187
// An enum describing why we did/are disconnecting:
188188
enum Disconnect {
189189
// Rust-Lightning told us to disconnect, either by returning an Err or by calling
@@ -338,7 +338,7 @@ where
338338

339339
let handle_opt = if peer_manager
340340
.as_ref()
341-
.new_inbound_connection(SocketDescriptor::new(us.clone()), remote_addr)
341+
.new_inbound_connection(SocketDescriptor::new(Arc::clone(&us)), remote_addr)
342342
.is_ok()
343343
{
344344
let handle = tokio::spawn(Connection::schedule_read(
@@ -391,7 +391,7 @@ where
391391
let last_us = Arc::clone(&us);
392392
let handle_opt = if let Ok(initial_send) = peer_manager.as_ref().new_outbound_connection(
393393
their_node_id,
394-
SocketDescriptor::new(us.clone()),
394+
SocketDescriptor::new(Arc::clone(&us)),
395395
remote_addr,
396396
) {
397397
let handle = tokio::spawn(async move {
@@ -402,7 +402,7 @@ where
402402
// and use a relatively tight timeout.
403403
let send_fut = async {
404404
loop {
405-
match SocketDescriptor::new(us.clone()).send_data(&initial_send, true) {
405+
match SocketDescriptor::new(Arc::clone(&us)).send_data(&initial_send, true) {
406406
v if v == initial_send.len() => break Ok(()),
407407
0 => {
408408
write_receiver.recv().await;

0 commit comments

Comments
 (0)