You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2017/12/10 11:19:34 UTC

[2/2] groovy git commit: Refine UnlimitedConcurrentCache

Refine UnlimitedConcurrentCache

(cherry picked from commit e26394b)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: e33151a8cd09468f69bdceb0419c527ad9106a37
Parents: c04a9e3
Author: sunlan <su...@apache.org>
Authored: Sun Dec 10 19:03:33 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Sun Dec 10 19:19:22 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/e33151a8/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);
+            }
         }
     }
 }