]> Untitled Git - bdk/commitdiff
docs(wallet): Explain `.take` usage
author志宇 <hello@evanlinjin.me>
Tue, 10 Dec 2024 10:56:37 +0000 (21:56 +1100)
committer志宇 <hello@evanlinjin.me>
Tue, 10 Dec 2024 10:56:37 +0000 (21:56 +1100)
crates/wallet/src/wallet/mod.rs

index 542db3b0664bcd4d2e16a1763792a0fd74f2d0a4..98559d4d96be23cff455fb1fcfaffac9486547b2 100644 (file)
@@ -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;