[jboss-cvs] JBossAS SVN: r59824 - branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/instrument.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jan 19 08:59:49 EST 2007


Author: kabir.khan at jboss.com
Date: 2007-01-19 08:59:49 -0500 (Fri, 19 Jan 2007)
New Revision: 59824

Modified:
   branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/instrument/ConstructorExecutionTransformer.java
Log:
Minor optimization, no need to first iterate over methods/ctors when classifying them and then while weaving

Modified: branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/instrument/ConstructorExecutionTransformer.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/instrument/ConstructorExecutionTransformer.java	2007-01-19 13:57:41 UTC (rev 59823)
+++ branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/instrument/ConstructorExecutionTransformer.java	2007-01-19 13:59:49 UTC (rev 59824)
@@ -127,7 +127,7 @@
    {
       return TransformerCommon.infoFromWeakReference(CONSTRUCTOR_INFO_CLASS_NAME, localName, ctorInfoName);      
    }
-   
+
    /**
     * Transforms the constructor executions of this class according to the pointcuts
     * registered in <code>AspectManager</code>.
@@ -138,7 +138,7 @@
    public boolean transform(CtClass clazz, ClassAdvisor classAdvisor) throws Exception
    {
       List constructors = instrumentor.getConstructors(clazz);
-      JoinpointClassification[] classification = classifyConstructor(constructors, classAdvisor);
+//      JoinpointClassification[] classification = classifyConstructor(constructors, classAdvisor);
       boolean wrappersGenerated = false;
       boolean oneOrMoreWrapped = false;
       int i = 0;
@@ -149,40 +149,46 @@
       {
          firstConstructor = (CtConstructor) constructors.get(0);
       }
-      for (Iterator iterator = constructors.iterator(); iterator.hasNext(); i++)
+      if (constructors.size() > 0)
       {
-         CtConstructor constructor = (CtConstructor) iterator.next();
-         if (classification[i] == JoinpointClassification.NOT_INSTRUMENTED
-               && !oneOrMoreWrapped)
+         for (Iterator iterator = constructors.iterator(); iterator.hasNext(); i++)
          {
-            continue;
-         }
-         else if (!wrappersGenerated)
-         {
-            //generateWrapper + prepareForWrapping
-            buildConstructorWrappers(clazz, classAdvisor);
-            wrappersGenerated = true;
-            wrapper.prepareForWrapping(firstConstructor, ALL_CONSTRUCTORS_STATUS);
-         }
-         
-         if (classification[i].equals(JoinpointClassification.WRAPPED))
-         {
-            if (!oneOrMoreWrapped)
+            CtConstructor constructor = (CtConstructor) iterator.next();
+            
+            JoinpointClassification classification = classifier.classifyConstructorExecution(constructor, classAdvisor);
+            
+            if (classification == JoinpointClassification.NOT_INSTRUMENTED
+                  && !oneOrMoreWrapped)
             {
-               for (int j = 0; j < i; j++)
+               continue;
+            }
+            else if (!wrappersGenerated)
+            {
+               //generateWrapper + prepareForWrapping
+               buildConstructorWrappers(clazz, classAdvisor);
+               wrappersGenerated = true;
+               wrapper.prepareForWrapping(firstConstructor, ALL_CONSTRUCTORS_STATUS);
+            }
+            
+            if (classification.equals(JoinpointClassification.WRAPPED))
+            {
+               if (!oneOrMoreWrapped)
                {
-                  this.setEmptyWrapperCodeLater((CtConstructor) constructors.get(j));
+                  for (int j = 0; j < i; j++)
+                  {
+                     this.setEmptyWrapperCodeLater((CtConstructor) constructors.get(j));
+                  }
+                  oneOrMoreWrapped = true;
                }
-               oneOrMoreWrapped = true;
+               wrap(clazz, constructor, i);
+               dynamicallyWrapped = dynamicallyWrapped || classification.equals(JoinpointClassification.DYNAMICALY_WRAPPED);
+               notDynamicallyWrapped = notDynamicallyWrapped || !classification.equals(JoinpointClassification.DYNAMICALY_WRAPPED);
             }
-            wrap(clazz, constructor, i);
-            dynamicallyWrapped = dynamicallyWrapped || classification[i].equals(JoinpointClassification.DYNAMICALY_WRAPPED);
-            notDynamicallyWrapped = notDynamicallyWrapped || !classification[i].equals(JoinpointClassification.DYNAMICALY_WRAPPED);
+            else if (oneOrMoreWrapped)
+            {
+               this.setEmptyWrapperCodeLater(constructor);
+            }
          }
-         else if (oneOrMoreWrapped)
-         {
-            this.setEmptyWrapperCodeLater(constructor);
-         }
       }
       
       if (oneOrMoreWrapped)
@@ -468,24 +474,6 @@
       return false;
    }
 
-   /**
-    * Classifies the constructor execution joinpoints.
-    * @param clazz the clazz whose constructors will be classified.
-    * @param advisor the advisor associated to <code>clazz</code>.
-    * @return a classification array.
-    */
-   protected JoinpointClassification[] classifyConstructor(List constructors, ClassAdvisor advisor) throws NotFoundException
-   {
-      JoinpointClassification[] classification = new JoinpointClassification[constructors.size()];
-      int index = 0;
-      for (Iterator iterator = constructors.iterator(); iterator.hasNext(); index++)
-      {
-         CtConstructor constructor = (CtConstructor) iterator.next();
-         classification[index] = classifier.classifyConstructorExecution(constructor, advisor);
-      }
-      return classification;
-   }
-   
    protected abstract void createWrapper(ConstructorTransformation trans) throws CannotCompileException, NotFoundException;
 
    protected void initialiseWrapper(int mod, CtConstructor constructor, int index) throws NotFoundException, CannotCompileException




More information about the jboss-cvs-commits mailing list