hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r899957 - /httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java
Date Sat, 16 Jan 2010 14:11:51 GMT
Author: sebb
Date: Sat Jan 16 14:11:50 2010
New Revision: 899957

URL: http://svn.apache.org/viewvc?rev=899957&view=rev
Log:
HTTPCLIENT-906 Minor performance improvement to IdleConnectionHandler
Replace keySet() + get() with entrySet()

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java?rev=899957&r1=899956&r2=899957&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java
Sat Jan 16 14:11:50 2010
@@ -27,8 +27,8 @@
 
 import java.io.IOException;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.http.annotation.NotThreadSafe;
@@ -118,11 +118,10 @@
         if (log.isDebugEnabled()) {
             log.debug("Checking for connections, idle timeout: "  + idleTimeout);
         }
-        Iterator<HttpConnection> connectionIter = connectionToTimes.keySet().iterator();
-        
-        while (connectionIter.hasNext()) {
-            HttpConnection conn = connectionIter.next();
-            TimeValues times = connectionToTimes.get(conn);
+
+        for (Entry<HttpConnection, TimeValues> entry : connectionToTimes.entrySet())
{
+            HttpConnection conn = entry.getKey();
+            TimeValues times = entry.getValue();
             long connectionTime = times.timeAdded;
             if (connectionTime <= idleTimeout) {
                 if (log.isDebugEnabled()) {
@@ -143,13 +142,10 @@
         if (log.isDebugEnabled()) {
             log.debug("Checking for expired connections, now: "  + now);
         }
-        
-        Iterator<HttpConnection> connectionIter =
-            connectionToTimes.keySet().iterator();
-        
-        while (connectionIter.hasNext()) {
-            HttpConnection conn = connectionIter.next();
-            TimeValues times = connectionToTimes.get(conn);
+
+        for (Entry<HttpConnection, TimeValues> entry : connectionToTimes.entrySet())
{
+            HttpConnection conn = entry.getKey();
+            TimeValues times = entry.getValue();
             if(times.timeExpires <= now) {
                 if (log.isDebugEnabled()) {
                     log.debug("Closing connection, expired @: "  + times.timeExpires);
@@ -160,7 +156,7 @@
                     log.debug("I/O error closing connection", ex);
                 }
             }
-        }        
+        }
     }
     
     private static class TimeValues {



Mime
View raw message