8142864: Raw types warning in WeakValueCache
authorhannesw
Thu, 12 Nov 2015 19:31:22 +0100
changeset 33695 f3f1bd0f638e
parent 33694 a48295df8eb9
child 33696 eee09e6b6e93
child 33883 5b2c96df2e1e
8142864: Raw types warning in WeakValueCache Reviewed-by: mhaupt, attila
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/WeakValueCache.java
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptRuntime.java
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/WeakValueCache.java	Thu Nov 12 19:51:43 2015 +0530
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/WeakValueCache.java	Thu Nov 12 19:31:22 2015 +0100
@@ -50,8 +50,20 @@
      * @return the value or null if none exists
      */
     public V get(final K key) {
-        removeClearedEntries();
-        return findValue(key);
+        // Remove cleared entries
+        for (;;) {
+            final KeyValueReference<?, ?> ref = (KeyValueReference) refQueue.poll();
+            if (ref == null) {
+                break;
+            }
+            map.remove(ref.key, ref);
+        }
+
+        final KeyValueReference<K, V> ref = map.get(key);
+        if (ref != null) {
+            return ref.get();
+        }
+        return null;
     }
 
     /**
@@ -63,9 +75,7 @@
      * @return the existing value, or a new one if none existed
      */
     public V getOrCreate(final K key, final Function<? super K, ? extends V> creator) {
-        removeClearedEntries();
-
-        V value = findValue(key);
+        V value = get(key);
 
         if (value == null) {
             // Define a new value if it does not exist
@@ -76,25 +86,6 @@
         return value;
     }
 
-    private V findValue(final K key) {
-        final KeyValueReference<K, V> ref = map.get(key);
-        if (ref != null) {
-            return ref.get();
-        }
-        return null;
-    }
-
-    private void removeClearedEntries() {
-        // Remove cleared entries
-        for (;;) {
-            final KeyValueReference ref = (KeyValueReference) refQueue.poll();
-            if (ref == null) {
-                break;
-            }
-            map.remove(ref.key, ref);
-        }
-    }
-
     private static class KeyValueReference<K, V> extends WeakReference<V> {
         final K key;
 
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptRuntime.java	Thu Nov 12 19:51:43 2015 +0530
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptRuntime.java	Thu Nov 12 19:31:22 2015 +0100
@@ -836,9 +836,9 @@
         } else if (yType == JSType.BOOLEAN) {
             // Can reverse order as y is primitive
             return equalBooleanToAny(y, x);
-        } else if (isWrappedPrimitiveAndObject(xType, yType)) {
+        } else if (isPrimitiveAndObject(xType, yType)) {
             return equalWrappedPrimitiveToObject(x, y);
-        } else if (isWrappedPrimitiveAndObject(yType, xType)) {
+        } else if (isPrimitiveAndObject(yType, xType)) {
             // Can reverse order as y is primitive
             return equalWrappedPrimitiveToObject(y, x);
         }
@@ -854,7 +854,7 @@
         return xType == JSType.NUMBER && yType == JSType.STRING;
     }
 
-    private static boolean isWrappedPrimitiveAndObject(final JSType xType, final JSType yType) {
+    private static boolean isPrimitiveAndObject(final JSType xType, final JSType yType) {
         return (xType == JSType.NUMBER || xType == JSType.STRING || xType == JSType.SYMBOL) && yType == JSType.OBJECT;
     }