From fc1e00058b5f9058d58b5e7a87a6fff57ff4b18a Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sat, 4 Nov 2023 16:41:17 -0400 Subject: [PATCH] wallet_showutxos: use O(1) check for frozen instead of O(n) utxo_d = [] for k, v in disabled.items(): utxo_d.append(k) {'frozen': True if u in utxo_d else False} The above was inefficient. Replace with: {'frozen': u in disabled} Checking for existence of a key in a dict takes time proportional to O(1), whereas checking for existence of an element in a list takes time proportional to O(n). --- src/jmclient/wallet_utils.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/jmclient/wallet_utils.py b/src/jmclient/wallet_utils.py index 3e29be2..d59096b 100644 --- a/src/jmclient/wallet_utils.py +++ b/src/jmclient/wallet_utils.py @@ -431,9 +431,6 @@ def wallet_showutxos(wallet_service, showprivkey): includeconfs=True) for md in utxos: (enabled, disabled) = get_utxos_enabled_disabled(wallet_service, md) - utxo_d = [] - for k, v in disabled.items(): - utxo_d.append(k) for u, av in utxos[md].items(): success, us = utxo_to_utxostr(u) assert success @@ -453,7 +450,7 @@ def wallet_showutxos(wallet_service, showprivkey): 'external': False, 'mixdepth': mixdepth, 'confirmations': av['confs'], - 'frozen': True if u in utxo_d else False} + 'frozen': u in disabled} if showprivkey: unsp[us]['privkey'] = wallet_service.get_wif_path(av['path']) if locktime: