[jboss-cvs] JBossAS SVN: r59825 - projects/aop/trunk/aop/src/main/org/jboss/aop/instrument.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jan 19 09:00:25 EST 2007


Author: kabir.khan at jboss.com
Date: 2007-01-19 09:00:25 -0500 (Fri, 19 Jan 2007)
New Revision: 59825

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

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructorExecutionTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructorExecutionTransformer.java	2007-01-19 13:59:49 UTC (rev 59824)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructorExecutionTransformer.java	2007-01-19 14:00:25 UTC (rev 59825)
@@ -138,7 +138,6 @@
    public boolean transform(CtClass clazz, ClassAdvisor classAdvisor) throws Exception
    {
       List constructors = instrumentor.getConstructors(clazz);
-      JoinpointClassification[] classification = classifyConstructor(constructors, classAdvisor);
       boolean wrappersGenerated = false;
       boolean oneOrMoreWrapped = false;
       int i = 0;
@@ -149,40 +148,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 +473,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

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodExecutionTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodExecutionTransformer.java	2007-01-19 13:59:49 UTC (rev 59824)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodExecutionTransformer.java	2007-01-19 14:00:25 UTC (rev 59825)
@@ -114,37 +114,19 @@
       return TransformerCommon.infoFromWeakReference(METHOD_INFO_CLASS_NAME, localName, methodInfoName);
    }
 
-   /**
-    * Classifies the method execution joinpoints.
-    *
-    * @param clazz   the clazz whose methods will be classified.
-    * @param advisor the advisor associated to <code>clazz</code>.
-    * @return a classification array.
-    */
-   protected JoinpointClassification[] classifyMethods(CtClass clazz, ClassAdvisor advisor) throws NotFoundException
-   {
-      CtMethod[] methods = clazz.getDeclaredMethods();
-      JoinpointClassification[] classification = new JoinpointClassification[methods.length];
-      for (int i = 0; i < methods.length; i++)
-      {
-         classification[i] = classifier.classifyMethodExecution(methods[i], advisor);
-      }
-      return classification;
-   }
-
    public void instrument(CtClass clazz, ClassAdvisor advisor)throws NotFoundException, CannotCompileException
    {
-      JoinpointClassification[] classification = classifyMethods(clazz, advisor);
       CtMethod[] methods = clazz.getDeclaredMethods();
       for (int i = 0; i < methods.length; i++)
       {
-         if (classification[i] == JoinpointClassification.NOT_INSTRUMENTED)
+         JoinpointClassification classification = classifier.classifyMethodExecution(methods[i], advisor);
+         if (classification == JoinpointClassification.NOT_INSTRUMENTED)
          {
             continue;
          }
          instrumentor.setupBasics(clazz);
          MethodTransformation trans = new MethodTransformation(instrumentor, clazz, methods[i]);
-         boolean wrap = (classification[i].equals(JoinpointClassification.WRAPPED));
+         boolean wrap = (classification.equals(JoinpointClassification.WRAPPED));
          transformMethod(trans, wrap);
 
          int modifier = trans.getWMethod().getModifiers();




More information about the jboss-cvs-commits mailing list