tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kkoli...@apache.org
Subject svn commit: r1624586 - in /tomcat/trunk/java/org/apache/tomcat/util/bcel: Constants.java classfile/Attribute.java
Date Fri, 12 Sep 2014 16:26:44 GMT
Author: kkolinko
Date: Fri Sep 12 16:26:44 2014
New Revision: 1624586

URL: http://svn.apache.org/r1624586
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.

Modified:
    tomcat/trunk/java/org/apache/tomcat/util/bcel/Constants.java
    tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Attribute.java

Modified: tomcat/trunk/java/org/apache/tomcat/util/bcel/Constants.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/bcel/Constants.java?rev=1624586&r1=1624585&r2=1624586&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/bcel/Constants.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/bcel/Constants.java Fri Sep 12 16:26:44 2014
@@ -91,25 +91,4 @@ public interface Constants {
     "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/trunk/java/org/apache/tomcat/util/bcel/classfile/Attribute.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Attribute.java?rev=1624586&r1=1624585&r2=1624586&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Attribute.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Attribute.java Fri Sep 12 16:26:44
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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message