You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2014/09/11 12:08:13 UTC

svn commit: r1624246 - in /tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile: Attribute.java Utility.java

Author: markt
Date: Thu Sep 11 10:08:12 2014
New Revision: 1624246

URL: http://svn.apache.org/r1624246
Log:
Improve efficiency of swallowAnnotations()

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

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=1624246&r1=1624245&r2=1624246&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 Thu Sep 11 10:08:12 2014
@@ -133,13 +133,13 @@ public abstract class Attribute implemen
             return new RuntimeVisibleAnnotations(name_index, length, file,
                     constant_pool);
         case Constants.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS:
-            Utility.swallowAnnotations(file, constant_pool);
+            Utility.swallowAnnotations(file);
             return null;
         case Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS:
             return new RuntimeVisibleParameterAnnotations(name_index, length,
                     file, constant_pool);
         case Constants.ATTR_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS:
-            Utility.swallowAnnotations(file, constant_pool);
+            Utility.swallowAnnotations(file);
             return null;
         case Constants.ATTR_ANNOTATION_DEFAULT:
             return new AnnotationDefault(name_index, length, file,

Modified: tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Utility.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Utility.java?rev=1624246&r1=1624245&r2=1624246&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Utility.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/bcel/classfile/Utility.java Thu Sep 11 10:08:12 2014
@@ -296,11 +296,57 @@ final class Utility {
         file.readUnsignedShort();   // Unused name_and_type_index
     }
 
-    static void swallowAnnotations(DataInputStream file, ConstantPool constant_pool)
+    static void swallowAnnotations(DataInput file)
             throws IOException {
         final int annotation_table_length = (file.readUnsignedShort());
         for (int i = 0; i < annotation_table_length; i++) {
-            AnnotationEntry.read(file, constant_pool);
+            swallowAnnotationEntry(file);
+        }
+    }
+
+    static void swallowAnnotationEntry(DataInput file)
+            throws IOException {
+        file.readUnsignedShort();   // Unused type index
+        final int num_element_value_pairs = (file.readUnsignedShort());
+        for (int i = 0; i < num_element_value_pairs; i++) {
+            file.readUnsignedShort();   // Unused name index
+            swallowElementValue(file);
+        }
+    }
+
+    static void swallowElementValue(DataInput file) throws IOException {
+
+        byte type = file.readByte();
+        switch (type) {
+        case 'B': // byte
+        case 'C': // char
+        case 'D': // double
+        case 'F': // float
+        case 'I': // int
+        case 'J': // long
+        case 'S': // short
+        case 'Z': // boolean
+        case 's': // String
+        case 'c': // Class
+            file.readUnsignedShort();   // Unused value index
+            break;
+        case 'e': // Enum constant
+            file.readUnsignedShort();   // Unused type_index
+            file.readUnsignedShort();   // Unused value index
+            break;
+        case '@': // Annotation
+            swallowAnnotationEntry(file);
+            break;
+        case '[': // Array
+            int numArrayVals = file.readUnsignedShort();
+            for (int j = 0; j < numArrayVals; j++)
+            {
+                swallowElementValue(file);
+            }
+            break;
+        default:
+            throw new RuntimeException(
+                    "Unexpected element value kind in annotation: " + type);
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org