Skip to content

Commit 19b3d3a

Browse files
committed
Use identity keys in dependency graph
1 parent f82eacf commit 19b3d3a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

vm/ByteCodeTranslator/src/com/codename1/tools/translator/MethodDependencyGraph.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
package com.codename1.tools.translator;
2525

2626
import java.util.ArrayList;
27+
import java.util.Collections;
2728
import java.util.HashMap;
2829
import java.util.HashSet;
30+
import java.util.IdentityHashMap;
2931
import java.util.List;
3032
import java.util.Map;
3133
import java.util.Set;
@@ -37,9 +39,13 @@
3739
*/
3840
public class MethodDependencyGraph {
3941
private final Map<String, Set<BytecodeMethod>> callersByLookupSignature = new HashMap<String, Set<BytecodeMethod>>();
40-
private final Map<BytecodeMethod, Set<String>> methodToCalls = new HashMap<BytecodeMethod, Set<String>>();
42+
private final Map<BytecodeMethod, Set<String>> methodToCalls = new IdentityHashMap<BytecodeMethod, Set<String>>();
4143
private final Map<String, Set<BytecodeMethod>> methodsByClass = new HashMap<String, Set<BytecodeMethod>>();
4244

45+
private static Set<BytecodeMethod> newIdentitySet() {
46+
return Collections.newSetFromMap(new IdentityHashMap<BytecodeMethod, Boolean>());
47+
}
48+
4349
public void clear() {
4450
callersByLookupSignature.clear();
4551
methodToCalls.clear();
@@ -49,7 +55,7 @@ public void clear() {
4955
public void registerMethod(BytecodeMethod method) {
5056
Set<BytecodeMethod> byClass = methodsByClass.get(method.getClsName());
5157
if (byClass == null) {
52-
byClass = new HashSet<BytecodeMethod>();
58+
byClass = newIdentitySet();
5359
methodsByClass.put(method.getClsName(), byClass);
5460
}
5561
byClass.add(method);
@@ -58,7 +64,7 @@ public void registerMethod(BytecodeMethod method) {
5864
public void recordMethodCall(BytecodeMethod caller, String calleeSignature) {
5965
Set<BytecodeMethod> callers = callersByLookupSignature.get(calleeSignature);
6066
if (callers == null) {
61-
callers = new HashSet<BytecodeMethod>();
67+
callers = newIdentitySet();
6268
callersByLookupSignature.put(calleeSignature, callers);
6369
}
6470
callers.add(caller);

0 commit comments

Comments
 (0)