made all field private

hashCode removed.
map the references via a combined string in references hash table


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@721 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 51d6e190ca
commit ff44d136a5
  1. 39
      jode/jode/bytecode/Reference.java

@ -25,62 +25,53 @@ package jode.bytecode;
import java.util.*; import java.util.*;
/** /**
* This class represents a field or method reference * This class represents a field or method reference.
*
* For simplicity currently most fields are public. You shouldn't change
* many of them, though.
*/ */
public class Reference { public class Reference {
/** /**
* The class info. * The class info.
*/ */
final String className; private final String className;
/** /**
* The member name. Don't make this a MethodInfo, since the clazz * The member name. Don't make this a MethodInfo, since the clazz
* may not be readable. * may not be readable.
*/ */
final String memberName; private final String memberName;
/** /**
* The member type. * The member type.
*/ */
final String memberType; private final String memberType;
/**
* The cached hash code
*/
final int cachedHashCode;
///#ifdef JDK12 ///#ifdef JDK12
/// private static final Map references = new WeakHashMap(); /// private static final Map references = new HashMap();
///#else ///#else
private static final Hashtable references = new Hashtable(); private static final Hashtable references = new Hashtable();
///#endif ///#endif
public static Reference getReference(String className, public static Reference getReference(String className,
String name, String type) { String name, String type) {
Reference reference = new Reference(className, name, type); String sig = className+" "+name+" "+type;
///#ifdef JDK12 ///#ifdef JDK12
/// WeakReference ref = (WeakReference) references.get(reference); /// WeakReference ref = (WeakReference) references.get(sig);
/// Reference cachedRef = (ref == null) ? null : (Reference) ref.get(); /// Reference reference = (ref == null) ? null : (Reference) ref.get();
///#else ///#else
Reference cachedRef = (Reference) references.get(reference); Reference reference = (Reference) references.get(sig);
///#endif ///#endif
if (cachedRef == null) { if (reference == null) {
reference = new Reference(className, name, type);
///#ifdef JDK12 ///#ifdef JDK12
/// references.put(reference, new WeakReference(reference)); /// references.put(sig, new WeakReference(reference));
///#else ///#else
references.put(reference, reference); references.put(reference, reference);
///#endif ///#endif
return reference;
} }
return cachedRef; return reference;
} }
private Reference(String className, String name, String type) { private Reference(String className, String name, String type) {
this.className = className.intern(); this.className = className.intern();
this.memberName = name.intern(); this.memberName = name.intern();
this.memberType = type.intern(); this.memberType = type.intern();
this.cachedHashCode =
className.hashCode() ^ name.hashCode() ^ type.hashCode();
} }
public String getClazz() { public String getClazz() {
@ -98,8 +89,4 @@ public class Reference {
public String toString() { public String toString() {
return className + " " + memberName + " " + memberType; return className + " " + memberName + " " + memberType;
} }
public int hashCode() {
return cachedHashCode;
}
} }

Loading…
Cancel
Save