Author: ljn1981
Date: 2006-09-20 17:12:03 +0000 (Wed, 20 Sep 2006)
New Revision: 10493

Modified:
   trunk/freenet/src/freenet/node/LocationManager.java
Log:
Optimizing and cleaning up the net size estimation code a bit.

Modified: trunk/freenet/src/freenet/node/LocationManager.java
===================================================================
--- trunk/freenet/src/freenet/node/LocationManager.java 2006-09-20 15:45:31 UTC 
(rev 10492)
+++ trunk/freenet/src/freenet/node/LocationManager.java 2006-09-20 17:12:03 UTC 
(rev 10493)
@@ -965,12 +965,13 @@
         Double dd = new Double(d);
         synchronized(knownLocs) {
             Date timestamp = new Date();
+            Long longTime = new Long(timestamp.getTime());
                        //If the location is already recorded, remove it from 
the hashmap
                        if (knownLocs.containsKey(dd)) {
                                knownLocs.remove(dd);
                        }
                        //Add the location to the map with the current 
timestamp as value
-                       knownLocs.put(dd,timestamp);
+                       knownLocs.put(dd,longTime);
                        if(logMINOR) Logger.minor(this, "Estimated net 
size(session): "+knownLocs.size());
         }
     }
@@ -983,17 +984,14 @@
                }
                else if (timestamp > -1) {
                        //TODO optimize some more if it is to be called a lot.
-                       Date threshold = new Date(timestamp);
-                       Date locationTime;
-                       int numberOfLocationsInPeriod = 0;
+                       Long locationTime;
                                Iterator knownLocationsIterator = 
knownLocs.values().iterator();
                                while (knownLocationsIterator.hasNext()) {
-                                       locationTime = (Date) 
knownLocationsIterator.next();
-                                       if (locationTime.after(threshold)) {
-                                               numberOfLocationsInPeriod++;
+                                       locationTime = (Long) 
knownLocationsIterator.next();
+                                       if (locationTime.longValue() > 
timestamp) {
+                                               size++;
                                        }
                                }
-                               size = numberOfLocationsInPeriod;
                        }
                        return size;
        }


Reply via email to