Skip to content

Commit

Permalink
remove uncessary clone in verify_queue
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Jan 18, 2024
1 parent 29bbcc1 commit 54c36ec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
9 changes: 9 additions & 0 deletions tx-pool/src/component/tests/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
9 changes: 4 additions & 5 deletions tx-pool/src/component/verify_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,19 @@ impl VerifyQueue {

/// Returns the first entry in the queue and remove it
pub fn pop_first(&mut self) -> Option<Entry> {
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<Entry> {
pub fn peak_first(&self) -> Option<ProposalShortId> {
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.
Expand Down
2 changes: 1 addition & 1 deletion tx-pool/src/verify_mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 54c36ec

Please sign in to comment.