Index: src/main/java/org/apache/harmony/unpack200/CpBands.java =================================================================== --- src/main/java/org/apache/harmony/unpack200/CpBands.java (revision 674741) +++ src/main/java/org/apache/harmony/unpack200/CpBands.java (working copy) @@ -83,6 +83,11 @@ private final HashMap doublesToCPDoubles = new HashMap(); private final HashMap descriptorsToCPNameAndTypes = new HashMap(); + private HashMap mapClass = new HashMap(); + private HashMap mapDescriptor = new HashMap(); + private HashMap mapUTF8 = new HashMap(); + private HashMap mapSignature = new HashMap(); + private int intOffset; private int floatOffset; private int longOffset; @@ -145,6 +150,7 @@ cpClass = new String[cpClassCount]; for (int i = 0; i < cpClassCount; i++) { cpClass[i] = cpUTF8[cpClassInts[i]]; + mapClass.put(cpClass[i], Integer.valueOf(i)); } } @@ -177,6 +183,7 @@ cpDescriptor = new String[cpDescriptorCount]; for (int i = 0; i < cpDescriptorCount; i++) { cpDescriptor[i] = cpDescriptorNames[i] + ":" + cpDescriptorTypes[i]; //$NON-NLS-1$ + mapDescriptor.put(cpDescriptor[i], Integer.valueOf(i)); } } @@ -356,10 +363,16 @@ } } cpSignature[i] = signature.toString(); + mapSignature.put(cpSignature[i], Integer.valueOf(i)); } for (int i = 0; i < cpSignatureInts.length; i++) { if(cpSignatureInts[i] == -1) { - cpSignatureInts[i] = search(cpUTF8, cpSignature[i]); + Integer indexN = (Integer)mapUTF8.get(cpSignature[i]); + if (indexN != null) { + cpSignatureInts[i] = indexN.intValue(); + } else { + cpSignatureInts[i] = -1; + } } } } @@ -392,6 +405,7 @@ int cpUTF8Count = header.getCpUTF8Count(); cpUTF8 = new String[cpUTF8Count]; cpUTF8[0] = ""; //$NON-NLS-1$ + mapUTF8.put("", Integer.valueOf(0)); int[] prefix = decodeBandInt("cpUTF8Prefix", in, Codec.DELTA5, cpUTF8Count - 2); int charCount = 0; @@ -440,10 +454,12 @@ // surprised if it works first time w/o errors ... cpUTF8[i] = lastString.substring(0, i > 1 ? prefix[i - 2] : 0) + new String(bigSuffixData[bigSuffixCount++]); + mapUTF8.put(cpUTF8[i], Integer.valueOf(i)); } else { cpUTF8[i] = lastString.substring(0, i > 1 ? prefix[i - 2] : 0) + new String(data, charCount, suffix[i - 1]); charCount += suffix[i - 1]; + mapUTF8.put(cpUTF8[i], Integer.valueOf(i)); } } } @@ -531,18 +547,18 @@ } CPUTF8 cputf8 = (CPUTF8) stringsToCPUTF8[domain].get(string); if (cputf8 == null) { - int index = -1; + Integer index = null; if(searchForIndex) { - index = search(cpUTF8, string); + index = (Integer)mapUTF8.get(string); } - if(index != -1) { - return cpUTF8Value(index, domain); + if(index != null) { + return cpUTF8Value(index.intValue(), domain); } if(searchForIndex) { - index = search(cpSignature, string); + index = (Integer)mapSignature.get(string); } - if(index != -1) { - return cpSignatureValue(index); + if(index != null) { + return cpSignatureValue(index.intValue()); } cputf8 = new CPUTF8(string, domain, -1); stringsToCPUTF8[domain].put(string, cputf8); @@ -609,9 +625,9 @@ public CPClass cpClassValue(String string) { CPClass cpString = (CPClass) stringsToCPClass.get(string); if (cpString == null) { - int index = search(cpClass, string); - if(index != -1) { - return cpClassValue(index); + Integer index = (Integer)mapClass.get(string); + if(index != null) { + return cpClassValue(index.intValue()); } cpString = new CPClass(cpUTF8Value(string, ClassConstantPool.DOMAIN_NORMALASCIIZ, false), -1); @@ -725,9 +741,9 @@ CPNameAndType cpNameAndType = (CPNameAndType) descriptorsToCPNameAndTypes .get(descriptor); if (cpNameAndType == null) { - int index = search(cpDescriptor, descriptor); - if(index != -1) { - return cpNameAndTypeValue(index); + Integer index = (Integer)mapDescriptor.get(descriptor); + if(index != null) { + return cpNameAndTypeValue(index.intValue()); } int descriptorDomain = ClassConstantPool.DOMAIN_UNDEFINED; int colon = descriptor.indexOf(':'); @@ -758,7 +774,7 @@ descriptorDomain = ClassConstantPool.DOMAIN_SIGNATUREASCIIZ; } CPUTF8 descriptorU = cpUTF8Value(descriptorString, descriptorDomain, true); - cpNameAndType = new CPNameAndType(name, descriptorU, domain, index + descrOffset); + cpNameAndType = new CPNameAndType(name, descriptorU, domain, index.intValue() + descrOffset); descriptorsToCPNameAndTypes.put(descriptor, cpNameAndType); } return cpNameAndType;