From 54c36ec12e49a83d875e5338f9ae8d37234567a8 Mon Sep 17 00:00:00 2001 From: yukang Date: Thu, 18 Jan 2024 18:30:03 +0800 Subject: [PATCH] remove uncessary clone in verify_queue --- tx-pool/src/component/tests/chunk.rs | 9 +++++++++ tx-pool/src/component/verify_queue.rs | 9 ++++----- tx-pool/src/verify_mgr.rs | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tx-pool/src/component/tests/chunk.rs b/tx-pool/src/component/tests/chunk.rs index c2ea1a0f1c..fcf0c37395 100644 --- a/tx-pool/src/component/tests/chunk.rs +++ b/tx-pool/src/component/tests/chunk.rs @@ -57,6 +57,15 @@ async fn verify_queue_basic() { let counts = count.await.unwrap(); assert_eq!(counts, vec![1, 1, 1, 2]); + let cur = queue.pop_first(); + assert_eq!(cur.unwrap().tx, tx); + + assert!(!queue.is_empty()); + let cur = queue.pop_first(); + assert_eq!(cur.unwrap().tx, tx2); + + assert!(queue.is_empty()); + queue.clear(); assert!(!queue.contains_key(&id)); } diff --git a/tx-pool/src/component/verify_queue.rs b/tx-pool/src/component/verify_queue.rs index 1da2add87f..d0192a7e27 100644 --- a/tx-pool/src/component/verify_queue.rs +++ b/tx-pool/src/component/verify_queue.rs @@ -103,20 +103,19 @@ impl VerifyQueue { /// Returns the first entry in the queue and remove it pub fn pop_first(&mut self) -> Option { - if let Some(entry) = self.get_first() { - self.remove_tx(&entry.tx.proposal_short_id()); - Some(entry) + if let Some(short_id) = self.peak_first() { + self.remove_tx(&short_id) } else { None } } /// Returns the first entry in the queue - pub fn get_first(&self) -> Option { + pub fn peak_first(&self) -> Option { self.inner .iter_by_added_time() .next() - .map(|entry| entry.inner.clone()) + .map(|entry| entry.inner.tx.proposal_short_id()) } /// If the queue did not have this tx present, true is returned. diff --git a/tx-pool/src/verify_mgr.rs b/tx-pool/src/verify_mgr.rs index b5ac11527d..18aabc11d7 100644 --- a/tx-pool/src/verify_mgr.rs +++ b/tx-pool/src/verify_mgr.rs @@ -77,7 +77,7 @@ impl Worker { return; } - if self.tasks.read().await.get_first().is_none() { + if self.tasks.read().await.peak_first().is_none() { return; } // pick a entry to run verify