Skip to content

Commit da801bf

Browse files
authored
Remove identity hash code usage (#13112)
1 parent 579ac95 commit da801bf

2 files changed

Lines changed: 4 additions & 26 deletions

File tree

dubbo-common/src/main/java/org/apache/dubbo/common/url/component/param/DynamicParamTable.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import org.apache.dubbo.rpc.model.FrameworkModel;
2020

21-
import java.util.Arrays;
2221
import java.util.Comparator;
2322
import java.util.HashMap;
2423
import java.util.LinkedList;
@@ -31,10 +30,6 @@
3130
* Not support method parameters
3231
*/
3332
public final class DynamicParamTable {
34-
/**
35-
* Keys array, value is key's identity hashcode ( assume key is in constant pool )
36-
*/
37-
private static int[] KEYS;
3833
/**
3934
* Keys array, value is string
4035
*/
@@ -54,13 +49,6 @@ public static int getKeyIndex(boolean enabled, String key) {
5449
if (!enabled) {
5550
return -1;
5651
}
57-
// assume key is in constant pool
58-
int identityHashCode = System.identityHashCode(key);
59-
int index = Arrays.binarySearch(KEYS, identityHashCode);
60-
if (index >= 0) {
61-
return index;
62-
}
63-
// fallback to key2index map
6452
Integer indexFromMap = KEY2INDEX.get(key);
6553
return indexFromMap == null ? -1 : indexFromMap;
6654
}
@@ -97,13 +85,6 @@ private static void init() {
9785
resultMap.put(keys.get(i), values.get(i));
9886
}
9987

100-
// assume key is in constant pool, store identity hashCode as index
101-
KEYS = resultMap.keySet()
102-
.stream()
103-
.map(System::identityHashCode)
104-
.mapToInt(x -> x)
105-
.toArray();
106-
10788
ORIGIN_KEYS = resultMap.keySet().toArray(new String[0]);
10889

10990
VALUES = resultMap.values().toArray(new ParamValue[0]);

dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/listener/AbstractMetricsListener.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,14 @@
2525

2626
public abstract class AbstractMetricsListener<E extends MetricsEvent> implements MetricsListener<E> {
2727

28-
private final Map<Integer, Boolean> eventMatchCache = new ConcurrentHashMap<>();
28+
private final Map<Class<?>, Boolean> eventMatchCache = new ConcurrentHashMap<>();
2929

3030
/**
31-
* Only interested in events of the current listener's generic parameter type
31+
* Whether to support the general determination of event points depends on the event type
3232
*/
3333
public boolean isSupport(MetricsEvent event) {
34-
Boolean eventMatch = eventMatchCache.get(System.identityHashCode(event.getClass()));
35-
if (eventMatch == null) {
36-
eventMatch = ReflectionUtils.match(getClass(), AbstractMetricsListener.class, event);
37-
eventMatchCache.put(System.identityHashCode(event.getClass()), eventMatch);
38-
}
34+
Boolean eventMatch = eventMatchCache.computeIfAbsent(event.getClass(),
35+
clazz -> ReflectionUtils.match(getClass(), AbstractMetricsListener.class, event));
3936
return event.isAvailable() && eventMatch;
4037
}
4138

0 commit comments

Comments
 (0)