From 720c60b1f7aa8eb6af6860631db0d2a67fd9941f Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 29 Apr 1999 11:16:09 +0000 Subject: [PATCH] getReferenceAlias added cache aliases git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@712 379699f6-c40d-0410-875b-85095c16579e --- jode/jode/obfuscator/ClassBundle.java | 46 +++++++++++++++++++++------ 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/jode/jode/obfuscator/ClassBundle.java b/jode/jode/obfuscator/ClassBundle.java index e79b5fd..4bbb849 100644 --- a/jode/jode/obfuscator/ClassBundle.java +++ b/jode/jode/obfuscator/ClassBundle.java @@ -44,17 +44,45 @@ public class ClassBundle { basePackage.setPreserved(); } +///#ifdef JDK12 +/// private static final Map aliasesHash = new WeakHashMap(); +///#else + private static final Hashtable aliasesHash = new Hashtable(); +///#endif + public Reference getReferenceAlias(Reference ref) { + Reference alias = (Reference) aliasesHash.get(ref); + if (alias == null) { + Identifier ident = getIdentifier(ref); + String newType = getTypeAlias(ref.getType()); + if (ident == null) + alias = Reference.getReference + (ref.getClazz(), ref.getName(), newType); + else + alias = Reference.getReference + ("L"+ident.getParent().getFullAlias().replace('.','/')+';', + ident.getAlias(), newType); + aliasesHash.put(ref, alias); + } + return alias; + } + public String getTypeAlias(String typeSig) { - StringBuffer newSig = new StringBuffer(); - int index = 0, nextindex; - while ((nextindex = typeSig.indexOf('L', index)) != -1) { - newSig.append(typeSig.substring(index, nextindex+1)); - index = typeSig.indexOf(';', nextindex); - String alias = basePackage.findAlias - (typeSig.substring(nextindex+1, index).replace('/','.')); - newSig.append(alias.replace('.', '/')); + String alias = (String) aliasesHash.get(typeSig); + if (alias == null) { + StringBuffer newSig = new StringBuffer(); + int index = 0, nextindex; + while ((nextindex = typeSig.indexOf('L', index)) != -1) { + newSig.append(typeSig.substring(index, nextindex+1)); + index = typeSig.indexOf(';', nextindex); + String typeAlias = basePackage.findAlias + (typeSig.substring(nextindex+1, index).replace('/','.')); + newSig.append(typeAlias.replace('.', '/')); + } + alias = newSig.append(typeSig.substring(index)) + .toString().intern(); + aliasesHash.put(typeSig, alias); } - return newSig.append(typeSig.substring(index)).toString(); + return alias; } public ClassIdentifier getClassIdentifier(String name) {