Repository: groovy
Updated Branches:
  refs/heads/master 5a16022eb -> e26394b15


Refine UnlimitedConcurrentCache


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

Branch: refs/heads/master
Commit: e26394b154cca57237688f5d5901ca5ce95785ef
Parents: 5a16022
Author: sunlan <[email protected]>
Authored: Sun Dec 10 19:03:33 2017 +0800
Committer: sunlan <[email protected]>
Committed: Sun Dec 10 19:03:33 2017 +0800

----------------------------------------------------------------------
 .../groovy/runtime/memoize/UnlimitedConcurrentCache.java    | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/e26394b1/src/main/org/codehaus/groovy/runtime/memoize/UnlimitedConcurrentCache.java
----------------------------------------------------------------------
diff --git 
a/src/main/org/codehaus/groovy/runtime/memoize/UnlimitedConcurrentCache.java 
b/src/main/org/codehaus/groovy/runtime/memoize/UnlimitedConcurrentCache.java
index 6dcdeba..874ab5d 100644
--- a/src/main/org/codehaus/groovy/runtime/memoize/UnlimitedConcurrentCache.java
+++ b/src/main/org/codehaus/groovy/runtime/memoize/UnlimitedConcurrentCache.java
@@ -19,7 +19,6 @@
 package org.codehaus.groovy.runtime.memoize;
 
 import java.lang.ref.SoftReference;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -45,11 +44,11 @@ public final class UnlimitedConcurrentCache implements 
MemoizeCache<Object, Obje
      * SoftReferences to gc-evicted objects.
      */
     public void cleanUpNullReferences() {
-        final Iterator<Map.Entry<Object, Object>> iterator = 
cache.entrySet().iterator();
-        while (iterator.hasNext()) {
-            final Map.Entry<Object, Object> entry = iterator.next();
+        for (Map.Entry<Object, Object> entry : cache.entrySet()) {
             Object entryVal = entry.getValue();
-            if (entryVal != null && ((SoftReference) entryVal).get() == null) 
cache.remove(entry.getKey(), entryVal);
+            if (entryVal instanceof SoftReference && ((SoftReference) 
entryVal).get() == null) {
+                cache.remove(entry.getKey(), entryVal);
+            }
         }
     }
 }

Reply via email to