Author: markt Date: Wed Sep 17 11:14:39 2014 New Revision: 1625515 URL: http://svn.apache.org/r1625515 Log: Simplify. There is no real need to convert every attribute name into numeric tag via lookup table, when there are only two attribute names that we recognize.
In the old code there was an average of (ATTRIBUTE_NAMES.length/2) = 11 String.equals() calls when looking up a numeric 'tag'. In the new code there will be two String.equals() calls. This is a backport of r1624586 from trunk Modified: tomcat/tc7.0.x/trunk/ (props changed) tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/ (props changed) tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/Constants.java tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Attribute.java Propchange: tomcat/tc7.0.x/trunk/ ------------------------------------------------------------------------------ Merged /tomcat/trunk:r1624586 Propchange: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/ ------------------------------------------------------------------------------ Merged /tomcat/trunk/java/org/apache/tomcat/util/bcel:r1624586 Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/Constants.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/Constants.java?rev=1625515&r1=1625514&r2=1625515&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/Constants.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/Constants.java Wed Sep 17 11:14:39 2014 @@ -90,26 +90,4 @@ public interface Constants { "CONSTANT_Methodref", "CONSTANT_InterfaceMethodref", "CONSTANT_NameAndType", "", "", "CONSTANT_MethodHandle", "CONSTANT_MethodType", "", "CONSTANT_InvokeDynamic" }; - - - /** Attributes and their corresponding names. - */ - public static final byte ATTR_UNKNOWN = -1; - public static final byte ATTR_RUNTIME_VISIBLE_ANNOTATIONS = 12; - public static final byte ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS = 14; - public static final byte ATTR_ANNOTATION_DEFAULT = 16; - - public static final short KNOWN_ATTRIBUTES = 22; - - // TOFO: FIXXXXX - public static final String[] ATTRIBUTE_NAMES = { - "SourceFile", "ConstantValue", "Code", "Exceptions", - "LineNumberTable", "LocalVariableTable", - "InnerClasses", "Synthetic", "Deprecated", - "PMGClass", "Signature", "StackMap", - "RuntimeVisibleAnnotations", "RuntimeInvisibleAnnotations", - "RuntimeVisibleParameterAnnotations", "RuntimeInvisibleParameterAnnotations", - "AnnotationDefault", "LocalVariableTypeTable", "EnclosingMethod", "StackMapTable", - "BootstrapMethods", "MethodParameters" - }; } Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Attribute.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Attribute.java?rev=1625515&r1=1625514&r2=1625515&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Attribute.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Attribute.java Wed Sep 17 11:14:39 2014 @@ -55,7 +55,6 @@ public abstract class Attribute { String name; int name_index; int length; - byte tag = Constants.ATTR_UNKNOWN; // Unknown attribute // Get class name from constant pool via `name_index' indirection name_index = file.readUnsignedShort(); c = (ConstantUtf8) constant_pool.getConstant(name_index, @@ -63,24 +62,14 @@ public abstract class Attribute { name = c.getBytes(); // Length of data in bytes length = file.readInt(); - // Compare strings to find known attribute - // System.out.println(name); - for (byte i = 0; i < Constants.KNOWN_ATTRIBUTES; i++) - { - if (name.equals(Constants.ATTRIBUTE_NAMES[i])) - { - tag = i; // found! - break; - } - } - // Call proper constructor, depending on `tag' - switch (tag) - { - case Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS: + + // Call proper constructor, depending on `name' + if (name.equals("RuntimeVisibleAnnotations")) { return new RuntimeVisibleAnnotations(file, constant_pool); - case Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS: + } else if (name.equals("RuntimeVisibleParameterAnnotations")) { return new RuntimeVisibleParameterAnnotations(file, constant_pool); - default: // All other attributes are skipped + } else { + // All other attributes are skipped Utility.skipFully(file, length); return null; } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org