diff options
author | aclement <aclement> | 2009-09-28 16:39:46 +0000 |
---|---|---|
committer | aclement <aclement> | 2009-09-28 16:39:46 +0000 |
commit | 6913762cc4a151dce9cd73e09b376793851131e6 (patch) | |
tree | 66ace1865385a81125fd45a212d7dc9f46a28901 | |
parent | 136fe84334f06836779b4e890d6ac225d0afc6b0 (diff) | |
download | aspectj-6913762cc4a151dce9cd73e09b376793851131e6.tar.gz aspectj-6913762cc4a151dce9cd73e09b376793851131e6.zip |
optimization
3 files changed, 44 insertions, 46 deletions
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Utility.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Utility.java index 5094299a5..6845139a3 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Utility.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Utility.java @@ -75,7 +75,7 @@ import org.aspectj.apache.bcel.util.ByteSequence; /** * Utility functions that do not really belong to any class in particular. * - * @version $Id: Utility.java,v 1.13 2009/09/28 16:35:18 aclement Exp $ + * @version $Id: Utility.java,v 1.14 2009/09/28 16:39:46 aclement Exp $ * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> * * modified: Andy Clement 2-mar-05 Removed unnecessary static and optimized @@ -200,11 +200,9 @@ public abstract class Utility { * @return Compacted class name */ public static final String compactClassName(String str, String prefix, boolean chopit) { - int len = prefix.length(); - str = str.replace('/', '.'); - if (chopit) { + int len = prefix.length(); // If string starts with 'prefix' and contains no further dots if (str.startsWith(prefix)) { String result = str.substring(len); @@ -370,21 +368,23 @@ public abstract class Utility { case 'L': { // Full class name int index = signature.indexOf(';'); // Look for closing ';' - if (index != -1 && signature.length() > index + 1 && signature.charAt(index + 1) == '>') { - index = index + 2; - } - if (index < 0) { throw new ClassFormatException("Invalid signature: " + signature); } + if (signature.length() > index + 1 && signature.charAt(index + 1) == '>') { + index = index + 2; + } + int genericStart = signature.indexOf('<'); - int genericEnd = signature.indexOf('>'); if (genericStart != -1) { + int genericEnd = signature.indexOf('>'); // FIXME asc going to need a lot more work in here for generics ResultHolder rh = signatureToStringInternal(signature.substring(genericStart + 1, genericEnd), chopit); - ResultHolder retval = new ResultHolder(compactClassName(signature.substring(1, genericStart) + "<" - + rh.getResult() + ">", chopit), genericEnd + 1); + StringBuffer sb = new StringBuffer(); + sb.append(signature.substring(1, genericStart)); + sb.append("<").append(rh.getResult()).append(">"); + ResultHolder retval = new ResultHolder(compactClassName(sb.toString(), chopit), genericEnd + 1); return retval; } else { processedChars = index + 1; // "Lblabla;" `L' and `;' are removed @@ -408,11 +408,10 @@ public abstract class Utility { brackets.append("[]"); } consumedChars = n; - // The rest of the string denotes a '<field_type>' ResultHolder restOfIt = signatureToStringInternal(signature.substring(n), chopit); - consumedChars += restOfIt.getConsumedChars(); - return new ResultHolder(restOfIt.getResult() + brackets.toString(), consumedChars); + brackets.insert(0, restOfIt.getResult()); + return new ResultHolder(brackets.toString(), consumedChars); } case 'V': return ResultHolder.VOID; diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionHandle.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionHandle.java index 72acb031d..d114a600e 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionHandle.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionHandle.java @@ -68,7 +68,7 @@ import org.aspectj.apache.bcel.classfile.Utility; * doubly-linked list. From the outside only the next and the previous instruction (handle) are accessible. One can traverse the * list via an Enumeration returned by InstructionList.elements(). * - * @version $Id: InstructionHandle.java,v 1.7 2009/09/09 19:56:20 aclement Exp $ + * @version $Id: InstructionHandle.java,v 1.8 2009/09/28 16:39:46 aclement Exp $ * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> * @see Instruction * @see BranchHandle @@ -78,7 +78,7 @@ public class InstructionHandle implements java.io.Serializable { InstructionHandle next, prev; // Will be set from the outside Instruction instruction; protected int i_position = -1; // byte code offset of instruction - private HashSet<InstructionTargeter> targeters; + private Set<InstructionTargeter> targeters = Collections.emptySet(); public final InstructionHandle getNext() { return next; @@ -155,9 +155,7 @@ public class InstructionHandle implements java.io.Serializable { * Remove all targeters, if any. */ public void removeAllTargeters() { - if (targeters != null) { - targeters.clear(); - } + targeters.clear(); } /** @@ -171,35 +169,27 @@ public class InstructionHandle implements java.io.Serializable { * Denote this handle is being referenced by t. */ public void addTargeter(InstructionTargeter t) { - if (targeters == null) { + if (targeters == Collections.EMPTY_SET) { targeters = new HashSet<InstructionTargeter>(); } - - // if(!targeters.contains(t)) targeters.add(t); } public boolean hasTargeters() { - return targeters != null && targeters.size() > 0; + return !targeters.isEmpty(); } - public InstructionTargeter[] getTargetersArray() { - if (!hasTargeters()) { - return null; - } - - InstructionTargeter[] t = new InstructionTargeter[targeters.size()]; - targeters.toArray(t); - return t; - } public Set<InstructionTargeter> getTargeters() { - if (targeters == null || targeters.size() == 0) { - return Collections.EMPTY_SET; - } return targeters; } + public Set<InstructionTargeter> getTargetersCopy() { + Set<InstructionTargeter> copy = new HashSet<InstructionTargeter>(); + copy.addAll(targeters); + return copy; + } + /** * @return a (verbose) string representation of the contained instruction. */ diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/ObjectType.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/ObjectType.java index 465805803..95e467529 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/ObjectType.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/ObjectType.java @@ -60,18 +60,27 @@ import org.aspectj.apache.bcel.classfile.JavaClass; /** * Denotes reference such as java.lang.String. * - * @version $Id: ObjectType.java,v 1.6 2009/09/28 16:34:37 aclement Exp $ + * @version $Id: ObjectType.java,v 1.7 2009/09/28 16:39:46 aclement Exp $ * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> */ public class ObjectType extends ReferenceType { - private String class_name; // Class name of type + private String classname; /** * @param class_name fully qualified class name, e.g. java.lang.String */ public ObjectType(String class_name) { super(Constants.T_REFERENCE, toSignature(class_name));// "L" + class_name.replace('.', '/') + ";"); - this.class_name = class_name;// .replace('/', '.'); + this.classname = class_name;// .replace('/', '.'); + } + + /** + * @param classname eg. java.lang.String + * @param signature eg. Ljava/lang/String; + */ + public ObjectType(String classname, String signature) { + super(Constants.T_REFERENCE, signature); + this.classname = classname; } private static String toSignature(String classname) { @@ -85,7 +94,7 @@ public class ObjectType extends ReferenceType { * @return name of referenced class */ public String getClassName() { - return class_name; + return classname; } /** @@ -93,7 +102,7 @@ public class ObjectType extends ReferenceType { */ @Override public int hashCode() { - return class_name.hashCode(); + return classname.hashCode(); } /** @@ -101,14 +110,14 @@ public class ObjectType extends ReferenceType { */ @Override public boolean equals(Object type) { - return (type instanceof ObjectType) ? ((ObjectType) type).class_name.equals(class_name) : false; + return (type instanceof ObjectType) ? ((ObjectType) type).classname.equals(classname) : false; } /** * If "this" doesn't reference a class, it references an interface or a non-existant entity. */ public boolean referencesClass() { - JavaClass jc = Repository.lookupClass(class_name); + JavaClass jc = Repository.lookupClass(classname); if (jc == null) { return false; } else { @@ -120,7 +129,7 @@ public class ObjectType extends ReferenceType { * If "this" doesn't reference an interface, it references a class or a non-existant entity. */ public boolean referencesInterface() { - JavaClass jc = Repository.lookupClass(class_name); + JavaClass jc = Repository.lookupClass(classname); if (jc == null) { return false; } else { @@ -133,19 +142,19 @@ public class ObjectType extends ReferenceType { return false; } - return Repository.instanceOf(this.class_name, superclass.class_name); + return Repository.instanceOf(this.classname, superclass.classname); } /** * Java Virtual Machine Specification edition 2, § 5.4.4 Access Control */ public boolean accessibleTo(ObjectType accessor) { - JavaClass jc = Repository.lookupClass(class_name); + JavaClass jc = Repository.lookupClass(classname); if (jc.isPublic()) { return true; } else { - JavaClass acc = Repository.lookupClass(accessor.class_name); + JavaClass acc = Repository.lookupClass(accessor.classname); return acc.getPackageName().equals(jc.getPackageName()); } } |