From: 志宇 Date: Tue, 10 Dec 2024 10:56:37 +0000 (+1100) Subject: docs(wallet): Explain `.take` usage X-Git-Tag: v1.0.0-beta.6~2^2~3 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/%22example_cli/enum.Commands.html/struct.MemoryDatabase.html?a=commitdiff_plain;h=caa0f13d40d000229dd867e6c52039a0c897fed2;p=bdk docs(wallet): Explain `.take` usage --- diff --git a/crates/wallet/src/wallet/mod.rs b/crates/wallet/src/wallet/mod.rs index 542db3b0..98559d4d 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;