3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-01 07:42:17 +00:00

No-op: auto-simplify a few constructs

This commit is contained in:
Mike Hearn 2013-03-11 14:58:47 +01:00
parent ac8a5008fe
commit 4d01e107fa

View File

@ -330,8 +330,7 @@ public class Peer {
// in the chain). // in the chain).
// //
// We go through and cancel the pending getdata futures for the items we were told weren't found. // We go through and cancel the pending getdata futures for the items we were told weren't found.
for (ListIterator<GetDataRequest> it = getDataFutures.listIterator(); it.hasNext();) { for (GetDataRequest req : getDataFutures) {
GetDataRequest req = it.next();
for (InventoryItem item : m.getItems()) { for (InventoryItem item : m.getItems()) {
if (item.hash.equals(req.hash)) { if (item.hash.equals(req.hash)) {
req.future.cancel(true); req.future.cancel(true);
@ -461,8 +460,7 @@ public class Peer {
return; return;
} }
// It's a broadcast transaction. Tell all wallets about this tx so they can check if it's relevant or not. // It's a broadcast transaction. Tell all wallets about this tx so they can check if it's relevant or not.
for (ListIterator<Wallet> it = wallets.listIterator(); it.hasNext(); ) { for (final Wallet wallet : wallets) {
final Wallet wallet = it.next();
try { try {
if (wallet.isPendingTransactionRelevant(fTx)) { if (wallet.isPendingTransactionRelevant(fTx)) {
// This transaction seems interesting to us, so let's download its dependencies. This has several // This transaction seems interesting to us, so let's download its dependencies. This has several
@ -637,8 +635,7 @@ public class Peer {
ping(nonce).addListener(new Runnable() { ping(nonce).addListener(new Runnable() {
public void run() { public void run() {
// The pong came back so clear out any transactions we requested but didn't get. // The pong came back so clear out any transactions we requested but didn't get.
for (ListIterator<GetDataRequest> it = getDataFutures.listIterator(); it.hasNext();) { for (GetDataRequest req : getDataFutures) {
GetDataRequest req = it.next();
if (req.nonce == nonce) { if (req.nonce == nonce) {
req.future.cancel(true); req.future.cancel(true);
getDataFutures.remove(req); getDataFutures.remove(req);
@ -757,8 +754,7 @@ public class Peer {
private boolean maybeHandleRequestedData(Message m) { private boolean maybeHandleRequestedData(Message m) {
boolean found = false; boolean found = false;
Sha256Hash hash = m.getHash(); Sha256Hash hash = m.getHash();
for (ListIterator<GetDataRequest> it = getDataFutures.listIterator(); it.hasNext();) { for (GetDataRequest req : getDataFutures) {
GetDataRequest req = it.next();
if (hash.equals(req.hash)) { if (hash.equals(req.hash)) {
req.future.set(m); req.future.set(m);
getDataFutures.remove(req); getDataFutures.remove(req);
@ -1119,8 +1115,8 @@ public class Peer {
public void complete() { public void complete() {
Preconditions.checkNotNull(future, "Already completed"); Preconditions.checkNotNull(future, "Already completed");
Long elapsed = Long.valueOf(Utils.now().getTime() - startTimeMsec); Long elapsed = Utils.now().getTime() - startTimeMsec;
Peer.this.addPingTimeData(elapsed.longValue()); Peer.this.addPingTimeData(elapsed);
log.debug("{}: ping time is {} msec", Peer.this.toString(), elapsed); log.debug("{}: ping time is {} msec", Peer.this.toString(), elapsed);
future.set(elapsed); future.set(elapsed);
future = null; future = null;
@ -1201,12 +1197,10 @@ public class Peer {
} }
private void processPong(Pong m) { private void processPong(Pong m) {
// This does not need to be locked.
PendingPing ping = null; PendingPing ping = null;
// Iterates over a snapshot of the list, so we can run unlocked here. // Iterates over a snapshot of the list, so we can run unlocked here.
ListIterator<PendingPing> it = pendingPings.listIterator(); for (PendingPing pendingPing : pendingPings) {
while (it.hasNext()) { ping = pendingPing;
ping = it.next();
if (m.getNonce() == ping.nonce) { if (m.getNonce() == ping.nonce) {
pendingPings.remove(ping); pendingPings.remove(ping);
break; break;