mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-23 16:55:09 +00:00
8142864: Raw types warning in WeakValueCache
Reviewed-by: mhaupt, attila
This commit is contained in:
parent
5b33de6a32
commit
898d1b3cf0
@ -50,8 +50,20 @@ public final class WeakValueCache<K, V> {
|
||||
* @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 @@ public final class WeakValueCache<K, V> {
|
||||
* @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 @@ public final class WeakValueCache<K, V> {
|
||||
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;
|
||||
|
||||
|
||||
@ -836,9 +836,9 @@ public final class ScriptRuntime {
|
||||
} 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 @@ public final class ScriptRuntime {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user