From c632dcf868f38ecef1ae2cab5daff650f8a48e1b Mon Sep 17 00:00:00 2001 From: Monica Moniot Date: Tue, 21 Nov 2023 15:46:33 -0500 Subject: [PATCH] cargo clippy --- performance/examples/basic_test.rs | 2 +- performance/examples/benchmark.rs | 2 +- performance/src/frag_cache.rs | 56 ++++++++++++++-------------- reference/examples/extensive_test.rs | 2 +- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/performance/examples/basic_test.rs b/performance/examples/basic_test.rs index ea749d4..ecde22c 100644 --- a/performance/examples/basic_test.rs +++ b/performance/examples/basic_test.rs @@ -166,7 +166,7 @@ fn alice_main( alice_app, |b: &mut [u8]| alice_out.send(b.to_vec()).is_ok(), TEST_MTU, - bob_pubkey.clone(), + bob_pubkey, 0, &[], ); diff --git a/performance/examples/benchmark.rs b/performance/examples/benchmark.rs index 513c486..02c060f 100644 --- a/performance/examples/benchmark.rs +++ b/performance/examples/benchmark.rs @@ -136,7 +136,7 @@ fn alice_main( alice_app, |b: &mut [u8]| alice_out.send(alloc(b)).is_ok(), TEST_MTU, - bob_pubkey.clone(), + bob_pubkey, (), &[], ); diff --git a/performance/src/frag_cache.rs b/performance/src/frag_cache.rs index 9390147..a8a09ec 100644 --- a/performance/src/frag_cache.rs +++ b/performance/src/frag_cache.rs @@ -317,39 +317,37 @@ fn test_cache() { assert!(assembled.is_empty(), "Cache returned an incomplete packet"); } } - if r > 200 { - if in_progress.len() > 0 { - let to_remain = (xorshift64_random() as usize % in_progress_fragments) + 16; - while in_progress_fragments > to_remain { - let (id, fragment_count, mut packet) = - in_progress.swap_remove(xorshift64_random() as usize % in_progress.len()); - for _ in 0..((xorshift64_random() as usize % packet.len()) + 1) { - let (no, fragment) = packet.swap_remove(xorshift64_random() as usize % packet.len()); + if r > 200 && !in_progress.is_empty() { + let to_remain = (xorshift64_random() as usize % in_progress_fragments) + 16; + while in_progress_fragments > to_remain { + let (id, fragment_count, mut packet) = + in_progress.swap_remove(xorshift64_random() as usize % in_progress.len()); + for _ in 0..((xorshift64_random() as usize % packet.len()) + 1) { + let (no, fragment) = packet.swap_remove(xorshift64_random() as usize % packet.len()); - assembled.clear(); - let mut nonce = [0; 12]; - nonce[..4].copy_from_slice(&id.to_be_bytes()); - cache.assemble( - &nonce, - 0, - fragment.len(), - fragment, - no as usize, - fragment_count as usize, - time, - &mut assembled, - ); - time += 200; - in_progress_fragments -= 1; + assembled.clear(); + let mut nonce = [0; 12]; + nonce[..4].copy_from_slice(&id.to_be_bytes()); + cache.assemble( + &nonce, + 0, + fragment.len(), + fragment, + no as usize, + fragment_count as usize, + time, + &mut assembled, + ); + time += 200; + in_progress_fragments -= 1; - if packet.len() > 0 { - assert!(assembled.is_empty(), "Cache returned an incomplete packet"); - } - } - if packet.len() > 0 { - in_progress.push((id, fragment_count, packet)); + if !packet.is_empty() { + assert!(assembled.is_empty(), "Cache returned an incomplete packet"); } } + if !packet.is_empty() { + in_progress.push((id, fragment_count, packet)); + } } } } diff --git a/reference/examples/extensive_test.rs b/reference/examples/extensive_test.rs index a568fe7..c5306ab 100644 --- a/reference/examples/extensive_test.rs +++ b/reference/examples/extensive_test.rs @@ -157,7 +157,7 @@ fn alice_main( &mut alice_app, |b| alice_out.send(b).is_ok(), TEST_MTU, - bob_pubkey.clone(), + bob_pubkey, 0, Vec::new(), )