From b2e335fbba7af9afd5216b414656d39c695ba262 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Sat, 24 Nov 2012 16:41:12 +0000 Subject: [PATCH] * Profiles: Small optimization in coalesceOnly() (ticket #765) javadoc, detab --- .../i2p/router/peermanager/PeerProfile.java | 20 +++++++++++++------ .../router/peermanager/ProfileOrganizer.java | 14 ++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/router/java/src/net/i2p/router/peermanager/PeerProfile.java b/router/java/src/net/i2p/router/peermanager/PeerProfile.java index 476f549c50..5a4ec66a2b 100644 --- a/router/java/src/net/i2p/router/peermanager/PeerProfile.java +++ b/router/java/src/net/i2p/router/peermanager/PeerProfile.java @@ -57,8 +57,6 @@ public class PeerProfile { // new calculation values, to be updated private double _speedValueNew; private double _capacityValueNew; - private double _integrationValueNew; - private boolean _isFailingNew; // are we in coalescing state? private boolean _coalescing; // good vs bad behavior @@ -515,6 +513,10 @@ public class PeerProfile { _log.debug("Coalesced: speed [" + _speedValue + "] capacity [" + _capacityValue + "] integration [" + _integrationValue + "] failing? [" + _isFailing + "]"); } + /** + * Caller must next call updateValues() + * @since 0.9.4 + */ void coalesceOnly() { _coalescing = true; @@ -533,10 +535,18 @@ public class PeerProfile { _speedValueNew = calculateSpeed(); _capacityValueNew = calculateCapacity(); - _integrationValueNew = calculateIntegration(); - _isFailingNew = calculateIsFailing(); + // These two are not used by InverseCapacityComparator + // to sort _strictCapacityOrder in ProfileOrganizer + // (in fact aren't really used at all), so we can + // update them directly + _integrationValue = calculateIntegration(); + _isFailing = calculateIsFailing(); } + /** + * Copy over the new values generated by coalesceOnly() + * @since 0.9.4 + */ void updateValues() { if (!_coalescing) // can happen coalesceOnly(); @@ -544,8 +554,6 @@ public class PeerProfile { _speedValue = _speedValueNew; _capacityValue = _capacityValueNew; - _integrationValue = _integrationValueNew; - _isFailing = _isFailingNew; } private double calculateSpeed() { return SpeedCalculator.calc(this); } diff --git a/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java b/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java index c7e45262b2..9248df85e5 100644 --- a/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java +++ b/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java @@ -782,9 +782,9 @@ public class ProfileOrganizer { } if (shouldCoalesce) { - getReadLock(); - try { - for (Iterator<PeerProfile> iter = _strictCapacityOrder.iterator(); iter.hasNext(); ) { + getReadLock(); + try { + for (Iterator<PeerProfile> iter = _strictCapacityOrder.iterator(); iter.hasNext(); ) { PeerProfile prof = iter.next(); if ( (expireOlderThan > 0) && (prof.getLastSendSuccessful() <= expireOlderThan) ) { continue; @@ -792,10 +792,10 @@ public class ProfileOrganizer { long coalesceStart = System.currentTimeMillis(); prof.coalesceOnly(); coalesceTime += (int)(System.currentTimeMillis()-coalesceStart); - } - } finally { - releaseReadLock(); - } + } + } finally { + releaseReadLock(); + } } if (!getWriteLock()) -- GitLab