From 39e7e5c4a1ca2a8c8ee45dcbe568eb553dfe6bc9 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 11 Oct 2013 10:22:23 -0500 Subject: [PATCH] Add minor optimization to transaction store fetch. This commit adds a quick check to the transaction store fetch code which simply returns an empty store if no hashes were requested rather than bothering the db with an empty list. --- txlookup.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/txlookup.go b/txlookup.go index 5b1ee446..8cf8dbb1 100644 --- a/txlookup.go +++ b/txlookup.go @@ -102,11 +102,16 @@ func disconnectTransactions(txStore TxStore, block *btcutil.Block) error { // fetchTxStoreMain fetches transaction data about the provided set of // transactions from the point of view of the end of the main chain. func fetchTxStoreMain(db btcdb.Db, txSet map[btcwire.ShaHash]bool) TxStore { + // Just return an empty store now if there are no requested hashes. + txStore := make(TxStore) + if len(txSet) == 0 { + return txStore + } + // The transaction store map needs to have an entry for every requested // transaction. By default, all the transactions are marked as missing. // Each entry will be filled in with the appropriate data below. txList := make([]*btcwire.ShaHash, 0, len(txSet)) - txStore := make(TxStore) for hash := range txSet { hashCopy := hash txStore[hash] = &TxData{Hash: &hashCopy, Err: btcdb.TxShaMissing}