Author: simonetripodi
Date: Thu Apr 19 20:20:24 2012
New Revision: 1328103

URL: http://svn.apache.org/viewvc?rev=1328103&view=rev
Log:
[DIGESTER-164] RulesBase performance optimization - patch provided by Frank 
David Martinez

Modified:
    
commons/proper/digester/trunk/annotations-processor/src/main/java/org/apache/commons/digester3/annotations/processor/DigesterAnnotationsProcessor.java
    
commons/proper/digester/trunk/annotations-processor/src/main/java/org/apache/commons/digester3/annotations/processor/DigesterElementVisitor.java
    
commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/RulesBase.java
    commons/proper/digester/trunk/src/changes/changes.xml

Modified: 
commons/proper/digester/trunk/annotations-processor/src/main/java/org/apache/commons/digester3/annotations/processor/DigesterAnnotationsProcessor.java
URL: 
http://svn.apache.org/viewvc/commons/proper/digester/trunk/annotations-processor/src/main/java/org/apache/commons/digester3/annotations/processor/DigesterAnnotationsProcessor.java?rev=1328103&r1=1328102&r2=1328103&view=diff
==============================================================================
--- 
commons/proper/digester/trunk/annotations-processor/src/main/java/org/apache/commons/digester3/annotations/processor/DigesterAnnotationsProcessor.java
 (original)
+++ 
commons/proper/digester/trunk/annotations-processor/src/main/java/org/apache/commons/digester3/annotations/processor/DigesterAnnotationsProcessor.java
 Thu Apr 19 20:20:24 2012
@@ -94,6 +94,7 @@ public class DigesterAnnotationsProcesso
         // processingEnv is a predefined member in AbstractProcessor class
         // Messager allows the processor to output messages to the environment
         final FormattingMessager messager = new FormattingMessager( 
processingEnv.getMessager() );
+        final DigesterElementVisitor elementVisitor = new 
DigesterElementVisitor( messager );
 
         // TODO get these values from -A parameters
         String packageName = getClass().getPackage().getName();
@@ -118,15 +119,20 @@ public class DigesterAnnotationsProcesso
             configureMethod.annotate( Override.class );
             final JBlock configureMethodBody = configureMethod.body();
 
+            for ( Element element : environment.getRootElements() )
+            {
+                element.accept( elementVisitor, null );
+            }
+
             // Loop through the annotations that we are going to process
-            for ( TypeElement annotation : annotations )
+            /* for ( TypeElement annotation : annotations )
             {
                 // Get the members
                 for ( Element element : environment.getElementsAnnotatedWith( 
annotation ) )
                 {
                     messager.error( "Processing @%s %s", annotation, element );
                 }
-            }
+            } */
 
             codeModel.build( new FilerCodeWriter( processingEnv.getFiler() ) );
 

Modified: 
commons/proper/digester/trunk/annotations-processor/src/main/java/org/apache/commons/digester3/annotations/processor/DigesterElementVisitor.java
URL: 
http://svn.apache.org/viewvc/commons/proper/digester/trunk/annotations-processor/src/main/java/org/apache/commons/digester3/annotations/processor/DigesterElementVisitor.java?rev=1328103&r1=1328102&r2=1328103&view=diff
==============================================================================
--- 
commons/proper/digester/trunk/annotations-processor/src/main/java/org/apache/commons/digester3/annotations/processor/DigesterElementVisitor.java
 (original)
+++ 
commons/proper/digester/trunk/annotations-processor/src/main/java/org/apache/commons/digester3/annotations/processor/DigesterElementVisitor.java
 Thu Apr 19 20:20:24 2012
@@ -69,6 +69,7 @@ final class DigesterElementVisitor
     @Override
     public Void visitType( TypeElement clazz, TypeElement annotation )
     {
+        System.out.println( ">>>>>>>>>" + clazz.getAnnotationMirrors() );
         messager.note( "visiting @%s on class %s", annotation, clazz );
         return null;
     }

Modified: 
commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/RulesBase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/RulesBase.java?rev=1328103&r1=1328102&r2=1328103&view=diff
==============================================================================
--- 
commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/RulesBase.java
 (original)
+++ 
commons/proper/digester/trunk/core/src/main/java/org/apache/commons/digester3/RulesBase.java
 Thu Apr 19 20:20:24 2012
@@ -21,6 +21,7 @@ package org.apache.commons.digester3;
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 
 import org.xml.sax.Attributes;
@@ -61,6 +62,11 @@ public class RulesBase
     protected HashMap<String, List<Rule>> cache = new HashMap<String, 
List<Rule>>();
 
     /**
+     * The subset of registered Rule instances with wildcard pattern.
+     */
+    protected List<String> wildcardCache = new LinkedList<String>();
+
+    /**
      * The set of registered Rule instances, in the order that they were 
originally registered.
      */
     protected ArrayList<Rule> rules = new ArrayList<Rule>();
@@ -99,6 +105,10 @@ public class RulesBase
         if ( list == null )
         {
             list = new ArrayList<Rule>();
+            if ( pattern.startsWith( "*/" ) )
+            {
+                wildcardCache.add( pattern.substring( 1 ) );
+            }
             cache.put( pattern, list );
         }
         list.add( rule );
@@ -110,6 +120,7 @@ public class RulesBase
      */
     public void clear()
     {
+        wildcardCache.clear();
         cache.clear();
         rules.clear();
     }
@@ -125,17 +136,18 @@ public class RulesBase
         {
             // Find the longest key, ie more discriminant
             String longKey = "";
-            for ( String key : cache.keySet() )
+            for ( String key : wildcardCache )
             {
-                if ( key.startsWith( "*/" )
-                                && ( pattern.equals( key.substring( 2 ) ) || 
pattern.endsWith( key.substring( 1 ) )
-                                && key.length() > longKey.length() ) )
+                if ( ( pattern.equals( key.substring( 1 ) ) || 
pattern.endsWith( key ) )
+                    && key.length() > longKey.length() )
                 {
-                    // rulesList = (List) this.cache.get(key);
-                    rulesList = lookup( namespaceURI, key );
                     longKey = key;
                 }
             }
+            if ( longKey.length() > 0 )
+            {
+                rulesList = lookup( namespaceURI, "*" + longKey );
+            }
         }
         if ( rulesList == null )
         {

Modified: commons/proper/digester/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/changes/changes.xml?rev=1328103&r1=1328102&r2=1328103&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/changes/changes.xml (original)
+++ commons/proper/digester/trunk/src/changes/changes.xml Thu Apr 19 20:20:24 
2012
@@ -23,6 +23,9 @@
   </properties>
   <body>
   <release version="3.3" date="201?-??-??" description="Maintenance release.">
+    <action dev="simonetripodi" type="fix" issue="DIGESTER-164" due-to="Frank 
David Martinez">
+      RulesBase performance optimization.
+    </action>
     <action dev="simonetripodi" type="fix" issue="DIGESTER-163" 
due-to="Torsten Krah">
       ConcurrentModificationException creating a new Digester via 
loaderInstance.newDigester()
     </action>


Reply via email to