commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattsic...@apache.org
Subject [27/50] [abbrv] commons-pool git commit: Fix POOL-307 Replace inefficient use of keySet with entrySet in GKOP.
Date Sun, 12 Mar 2017 19:47:57 GMT
Fix POOL-307
Replace inefficient use of keySet with entrySet in GKOP.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/pool/trunk@1735165 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/commons-pool/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-pool/commit/db15a295
Tree: http://git-wip-us.apache.org/repos/asf/commons-pool/tree/db15a295
Diff: http://git-wip-us.apache.org/repos/asf/commons-pool/diff/db15a295

Branch: refs/heads/master
Commit: db15a295e120fcd5d5ad74207d03edf09b24bb19
Parents: 564334a
Author: Mark Thomas <markt@apache.org>
Authored: Tue Mar 15 20:37:58 2016 +0000
Committer: Mark Thomas <markt@apache.org>
Committed: Tue Mar 15 20:37:58 2016 +0000

----------------------------------------------------------------------
 src/changes/changes.xml                         |  5 ++-
 .../pool2/impl/GenericKeyedObjectPool.java      | 42 +++++++++++---------
 2 files changed, 27 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-pool/blob/db15a295/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 30573e4..6b48a1f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -56,9 +56,12 @@ The <action> type attribute can be add,update,fix,remove.
       threads try to borrow an object at the same time and the factory fails to
       create any objects. 
     </action>
-    <action dev="markt" issue="POOL-280" tyoe="update" due-to="Jacopo Cappellato">
+    <action dev="markt" issue="POOL-280" type="update" due-to="Jacopo Cappellato">
       Small refactoring of borrowObject() to reduce code duplication.
     </action>
+    <action dev="markt" issue="POOL-307" type="update" due-to="Anthony Whitford">
+      Replace inefficient use of keySet with entrySet in GKOP.
+    </action>
   </release>
   <release version="2.4.2" date="2015-08-01" description=
  "This is a patch release, including bug fixes only.">

http://git-wip-us.apache.org/repos/asf/commons-pool/blob/db15a295/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java b/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
index 8e1f88f..20281ee 100644
--- a/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
+++ b/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
@@ -738,13 +738,14 @@ public class GenericKeyedObjectPool<K,T> extends BaseGenericObjectPool<T>
         // build sorted map of idle objects
         final Map<PooledObject<T>, K> map = new TreeMap<PooledObject<T>,
K>();
 
-        for (final K k : poolMap.keySet()) {
-            final ObjectDeque<T> queue = poolMap.get(k);
+        for (Map.Entry<K, ObjectDeque<T>> entry : poolMap.entrySet()) {
+            final K k = entry.getKey();
+            final ObjectDeque<T> deque = entry.getValue();
             // Protect against possible NPE if key has been removed in another
             // thread. Not worth locking the keys while this loop completes.
-            if (queue != null) {
+            if (deque != null) {
                 final LinkedBlockingDeque<PooledObject<T>> idleObjects =
-                    queue.getIdleObjects();
+                        deque.getIdleObjects();
                 for (final PooledObject<T> p : idleObjects) {
                     // each item into the map using the PooledObject object as the
                     // key. It then gets sorted based on the idle time
@@ -800,8 +801,9 @@ public class GenericKeyedObjectPool<K,T> extends BaseGenericObjectPool<T>
         int maxQueueLength = 0;
         LinkedBlockingDeque<PooledObject<T>> mostLoaded = null;
         K loadedKey = null;
-        for (final K k : poolMap.keySet()) {
-            final ObjectDeque<T> deque = poolMap.get(k);
+        for (Map.Entry<K, ObjectDeque<T>> entry : poolMap.entrySet()) {
+            final K k = entry.getKey();
+            final ObjectDeque<T> deque = entry.getValue();
             if (deque != null) {
                 final LinkedBlockingDeque<PooledObject<T>> pool = deque.getIdleObjects();
                 final int queueLength = pool.getTakeQueueLength();
@@ -837,8 +839,8 @@ public class GenericKeyedObjectPool<K,T> extends BaseGenericObjectPool<T>
      *         {@code false}
      */
     private boolean hasBorrowWaiters() {
-        for (final K k : poolMap.keySet()) {
-            final ObjectDeque<T> deque = poolMap.get(k);
+        for (Map.Entry<K, ObjectDeque<T>> entry : poolMap.entrySet()) {
+            final ObjectDeque<T> deque = entry.getValue();
             if (deque != null) {
                 final LinkedBlockingDeque<PooledObject<T>> pool =
                     deque.getIdleObjects();
@@ -1371,14 +1373,15 @@ public class GenericKeyedObjectPool<K,T> extends BaseGenericObjectPool<T>
     public Map<String,Integer> getNumWaitersByKey() {
         final Map<String,Integer> result = new HashMap<String,Integer>();
 
-        for (final K key : poolMap.keySet()) {
-            final ObjectDeque<T> queue = poolMap.get(key);
-            if (queue != null) {
+        for (Map.Entry<K, ObjectDeque<T>> entry : poolMap.entrySet()) {
+            final K k = entry.getKey();
+            final ObjectDeque<T> deque = entry.getValue();
+            if (deque != null) {
                 if (getBlockWhenExhausted()) {
-                    result.put(key.toString(), Integer.valueOf(
-                            queue.getIdleObjects().getTakeQueueLength()));
+                    result.put(k.toString(), Integer.valueOf(
+                            deque.getIdleObjects().getTakeQueueLength()));
                 } else {
-                    result.put(key.toString(), Integer.valueOf(0));
+                    result.put(k.toString(), Integer.valueOf(0));
                 }
             }
         }
@@ -1401,13 +1404,14 @@ public class GenericKeyedObjectPool<K,T> extends BaseGenericObjectPool<T>
         final Map<String,List<DefaultPooledObjectInfo>> result =
                 new HashMap<String,List<DefaultPooledObjectInfo>>();
 
-        for (final K key : poolMap.keySet()) {
-            final ObjectDeque<T> queue = poolMap.get(key);
-            if (queue != null) {
+        for (Map.Entry<K, ObjectDeque<T>> entry : poolMap.entrySet()) {
+            final K k = entry.getKey();
+            final ObjectDeque<T> deque = entry.getValue();
+            if (deque != null) {
                 final List<DefaultPooledObjectInfo> list =
                         new ArrayList<DefaultPooledObjectInfo>();
-                result.put(key.toString(), list);
-                for (final PooledObject<T> p : queue.getAllObjects().values()) {
+                result.put(k.toString(), list);
+                for (final PooledObject<T> p : deque.getAllObjects().values()) {
                     list.add(new DefaultPooledObjectInfo(p));
                 }
             }


Mime
View raw message