diff options
author | jonmv <venstad@gmail.com> | 2022-10-26 12:02:08 +0200 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2022-10-26 12:02:08 +0200 |
commit | f2fe167f4fdff5ed453773423d4b8a8aa36f3f78 (patch) | |
tree | c1bbf8b84262d76c22b1bacbad2256b719026532 /vespajlib | |
parent | 5246967ce8b8ac4a95c944be21a0f473175c4b2a (diff) |
Remove weak-refs
Diffstat (limited to 'vespajlib')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/collections/MethodCache.java | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java b/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java index d0da7617b58..2b8f7831a20 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java +++ b/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java @@ -3,7 +3,6 @@ package com.yahoo.collections; import com.yahoo.concurrent.CopyOnWriteHashMap; -import java.lang.ref.WeakReference; import java.lang.reflect.Method; import java.util.function.Consumer; @@ -17,7 +16,7 @@ import java.util.function.Consumer; public final class MethodCache { private final String methodName; - private final CopyOnWriteHashMap<String, WeakReference<Pair<Class<?>, Method>>> cache = new CopyOnWriteHashMap<>(); + private final CopyOnWriteHashMap<String, Pair<Class<?>, Method>> cache = new CopyOnWriteHashMap<>(); public MethodCache(String methodName) { this.methodName = methodName; @@ -36,8 +35,7 @@ public final class MethodCache { } public Method get(Object object, Consumer<String> onPut) { - WeakReference<Pair<Class<?>, Method>> value = cache.get(object.getClass().getName()); - Pair<Class<?>, Method> pair = value == null ? null : value.get(); + Pair<Class<?>, Method> pair = cache.get(object.getClass().getName()); if (pair != null && pair.getFirst() != object.getClass()) { cache.clear(); pair = null; @@ -45,8 +43,7 @@ public final class MethodCache { Method method = pair == null ? null : pair.getSecond(); if (pair == null) { method = lookupMethod(object); - pair = new Pair<>(object.getClass(), method); - cache.put(object.getClass().getName(), new WeakReference<>(pair)); + cache.put(object.getClass().getName(), new Pair<>(object.getClass(), method)); if (onPut != null) onPut.accept(object.getClass().getName()); } |