Skip to content

Use borrowed &str keys for existing_tx_map in process_wallet_transactions #247

@schjonhaug

Description

@schjonhaug

Context

In sync.rs, the existing_tx_map HashMap is built in three places with inconsistent key types:

Location Function Key type
~line 414 process_wallet_transactions HashMap<String, &_> (clones each txid)
~line 1545 check_address_watch_for_confirmations HashMap<&str, &_> (borrows, zero-copy)
~line 1832 check_grouped_address_watch_for_confirmations HashMap<&str, &_> (borrows, zero-copy)

The &str-keyed maps avoid heap allocation per entry. The main process_wallet_transactions function should use the same &str borrowing pattern for consistency and to avoid unnecessary String clones.

Proposed fix

Change line ~414 from:

let existing_tx_map: HashMap<String, &TransactionWithWallet> = existing_transactions
    .iter()
    .map(|tx| (tx.txid.clone(), tx))
    .collect();

To:

let existing_tx_map: HashMap<&str, &TransactionWithWallet> = existing_transactions
    .iter()
    .map(|tx| (tx.txid.as_str(), tx))
    .collect();

This requires updating lookup call sites to use .get(txid.as_str()) instead of .get(txid) where the key is a String.

Identified during PR #245 code review.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions