diff options
Diffstat (limited to 'src/proguard/classfile/editor/InterfaceSorter.java')
-rw-r--r-- | src/proguard/classfile/editor/InterfaceSorter.java | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/src/proguard/classfile/editor/InterfaceSorter.java b/src/proguard/classfile/editor/InterfaceSorter.java index 0d1f28c..a67b0a2 100644 --- a/src/proguard/classfile/editor/InterfaceSorter.java +++ b/src/proguard/classfile/editor/InterfaceSorter.java @@ -2,7 +2,7 @@ * ProGuard -- shrinking, optimization, obfuscation, and preverification * of Java bytecode. * - * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu) + * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu) * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free @@ -23,12 +23,11 @@ package proguard.classfile.editor; import proguard.classfile.*; import proguard.classfile.attribute.*; import proguard.classfile.attribute.visitor.AttributeVisitor; -import proguard.classfile.constant.*; -import proguard.classfile.constant.visitor.ConstantVisitor; +import proguard.classfile.constant.Utf8Constant; import proguard.classfile.util.*; import proguard.classfile.visitor.ClassVisitor; -import java.util.*; +import java.util.Arrays; /** * This ClassVisitor sorts the interfaces of the program classes that it visits. @@ -52,27 +51,30 @@ implements ClassVisitor, // Sort the interfaces. Arrays.sort(interfaces, 0, interfacesCount); + // Update the signature. + programClass.attributesAccept(this); + // Remove any duplicate entries. - int newInterfacesCount = 0; - int previousInterfaceIndex = 0; - for (int index = 0; index < interfacesCount; index++) + boolean[] delete = null; + for (int index = 1; index < interfacesCount; index++) { - int interfaceIndex = interfaces[index]; - - // Isn't this a duplicate of the previous interface? - if (interfaceIndex != previousInterfaceIndex) + Clazz interfaceClass = programClass.getInterface(index); + if (interfaces[index] == interfaces[index - 1]) { - interfaces[newInterfacesCount++] = interfaceIndex; + // Lazily create the array. + if (delete == null) + { + delete = new boolean[interfacesCount]; + } - // Remember the interface. - previousInterfaceIndex = interfaceIndex; + delete[index] = true; } } - programClass.u2interfacesCount = newInterfacesCount; - - // Update the signature, if any - programClass.attributesAccept(this); + if (delete != null) + { + new InterfaceDeleter(delete).visitProgramClass(programClass); + } } } @@ -86,7 +88,7 @@ implements ClassVisitor, { // Process the generic definitions, superclass, and implemented // interfaces. - String signature = clazz.getString(signatureAttribute.u2signatureIndex); + String signature = signatureAttribute.getSignature(clazz); // Count the signature types. InternalTypeEnumeration internalTypeEnumeration = @@ -127,13 +129,7 @@ implements ClassVisitor, for (int index = 0; index < count; index++) { - // Is this not an interface type, or an interface type that isn't - // a duplicate of the previous interface type? - if (index < count - interfacesCount || - !internalTypes[index].equals(internalTypes[index-1])) - { - newSignatureBuffer.append(internalTypes[index]); - } + newSignatureBuffer.append(internalTypes[index]); } String newSignature = newSignatureBuffer.toString(); |