From 57b47749852e90473eef233685147cbb1619db7c Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Mon, 18 Mar 2013 22:43:26 +0100 Subject: [PATCH] Clean up another listener invocation a bit. --- .../com/google/bitcoin/core/AbstractBlockChain.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/google/bitcoin/core/AbstractBlockChain.java b/core/src/main/java/com/google/bitcoin/core/AbstractBlockChain.java index 84697f82..c95ba182 100644 --- a/core/src/main/java/com/google/bitcoin/core/AbstractBlockChain.java +++ b/core/src/main/java/com/google/bitcoin/core/AbstractBlockChain.java @@ -450,8 +450,8 @@ public abstract class AbstractBlockChain { // If we do, send them to the wallet but state that they are on a side chain so it knows not to try and // spend them until they become activated. if (block.transactions != null || filteredTxn != null) { - for (int i = 0; i < listeners.size(); i++) { - BlockChainListener listener = listeners.get(i); + boolean first = true; + for (BlockChainListener listener : listeners) { List txnToNotify; if (block.transactions != null) txnToNotify = block.transactions; @@ -462,17 +462,13 @@ public abstract class AbstractBlockChain { // is relevant to both of them, they don't end up accidentally sharing the same object (which can // result in temporary in-memory corruption during re-orgs). See bug 257. We only duplicate in // the case of multiple wallets to avoid an unnecessary efficiency hit in the common case. - sendTransactionsToListener(newBlock, NewBlockType.SIDE_CHAIN, listener, txnToNotify, i > 0); + sendTransactionsToListener(newBlock, NewBlockType.SIDE_CHAIN, listener, txnToNotify, first); if (filteredTxHashList != null) { for (Sha256Hash hash : filteredTxHashList) { listener.notifyTransactionIsInBlock(hash, newBlock, NewBlockType.SIDE_CHAIN); } } - if (i == listeners.size()) { - break; // Listener removed itself and it was the last one. - } else if (listeners.get(i) != listener) { - i--; // Listener removed itself and it was not the last one. - } + first = false; } }