From caa0f13d40d000229dd867e6c52039a0c897fed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=97=E5=AE=87?= Date: Tue, 10 Dec 2024 21:56:37 +1100 Subject: [PATCH] docs(wallet): Explain `.take` usage --- crates/wallet/src/wallet/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/wallet/src/wallet/mod.rs b/crates/wallet/src/wallet/mod.rs index 542db3b06..98559d4d9 100644 --- a/crates/wallet/src/wallet/mod.rs +++ b/crates/wallet/src/wallet/mod.rs @@ -1844,6 +1844,9 @@ impl Wallet { .graph() .list_canonical_txs(&self.chain, chain_tip) .filter(|canon_tx| prev_txids.contains(&canon_tx.tx_node.txid)) + // This is for a small performance gain. Although `.filter` filters out excess txs, it + // will still consume the internal `CanonicalIter` entirely. Having a `.take` here + // allows us to stop further unnecessary canonicalization. .take(prev_txids.len()) .map(|canon_tx| { let txid = canon_tx.tx_node.txid;