2424package com .codename1 .tools .translator ;
2525
2626import java .util .ArrayList ;
27+ import java .util .Collections ;
2728import java .util .HashMap ;
2829import java .util .HashSet ;
30+ import java .util .IdentityHashMap ;
2931import java .util .List ;
3032import java .util .Map ;
3133import java .util .Set ;
3739 */
3840public 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