felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r806819 - /felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
Date Sat, 22 Aug 2009 09:11:19 GMT
Author: clement
Date: Sat Aug 22 09:11:19 2009
New Revision: 806819

URL: http://svn.apache.org/viewvc?rev=806819&view=rev
Log:
Fix FELIX-1518
Improve the performance of the manipulator by avoiding to read useless classes when annotations
are ignored.

Modified:
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java

Modified: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java?rev=806819&r1=806818&r2=806819&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
(original)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
Sat Aug 22 09:11:19 2009
@@ -452,6 +452,28 @@
         }
 
     }
+    
+    /**
+     * Reads the entry to extract the byte array.
+     * This method should be called only if the class has to be read.
+     * The cost of this method is not negligible.
+     * @param name name of the entry to read from the input jar
+     * @return the read byte array
+     * @throws IOException occurs when the entry cannot be read
+     */
+    private byte[] readEntry(String name) throws IOException {
+        InputStream currIn = getInputStream(name);
+        byte[] in = new byte[0];
+        int c;
+        while ((c = currIn.read()) >= 0) {
+            byte[] in2 = new byte[in.length + 1];
+            System.arraycopy(in, 0, in2, 0, in.length);
+            in2[in.length] = (byte) c;
+            in = in2;
+        }
+        currIn.close();
+        return in;
+    }
 
     /**
      * Manipulate classes of the input Jar.
@@ -462,17 +484,10 @@
         while (entries.hasMoreElements()) {
             String curName = (String) entries.nextElement();
             try {
-                InputStream currIn = getInputStream(curName);
-                byte[] in = new byte[0];
-                int c;
-                while ((c = currIn.read()) >= 0) {
-                    byte[] in2 = new byte[in.length + 1];
-                    System.arraycopy(in, 0, in2, 0, in.length);
-                    in2[in.length] = (byte) c;
-                    in = in2;
-                }
-                currIn.close();
+                byte[] in = null; // Will store the bytes of the entry if required.
                 if (!m_ignoreAnnotations) {
+                    // If we need to process annotations, all classes has to be read.
+                    in = readEntry(curName);
                     computeAnnotations(in); // This method adds the class to the
                                             // component list.
                 }
@@ -480,6 +495,11 @@
                 for (int i = 0; i < m_components.size(); i++) {
                     ComponentInfo ci = (ComponentInfo) m_components.get(i);
                     if (ci.m_classname.equals(curName)) {
+                        // So, we have to manipulate the class, if not already read, read
the input class
+                        // Else reuse the same one.
+                        if (in == null) {
+                            in = readEntry(curName);
+                        }
                         byte[] outClazz = manipulateComponent(in, ci);
                         m_classes.put(ci.m_classname, outClazz);
                         



Mime
View raw message