myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1004881 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces: application/ApplicationImpl.java context/RequestViewContext.java
Date Wed, 06 Oct 2010 02:35:58 GMT
Author: lu4242
Date: Wed Oct  6 02:35:57 2010
New Revision: 1004881

URL: http://svn.apache.org/viewvc?rev=1004881&view=rev
Log:
MYFACES-2922 [PERF] Improvements for @ResourceDependency handling (Thanks to Martin Koci for
provide this patch)

Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/RequestViewContext.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java?rev=1004881&r1=1004880&r2=1004881&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
Wed Oct  6 02:35:57 2010
@@ -1952,6 +1952,17 @@ public class ApplicationImpl extends App
 
     private void _handleResourceDependencyAnnotations(FacesContext context, Class<?>
inspectedClass, UIComponent component, boolean isProduction)
     {
+        // This and only this method handles @ResourceDependency and @ResourceDependencies
annotations
+        // The source of these annotations is Class<?> inspectedClass. Because Class<?>
and its annotations cannot change 
+        // during request/response, it is sufficient to process Class<?> only once
per view.
+        RequestViewContext rvc = RequestViewContext.getCurrentInstance(context);
+        if (rvc.isClassAlreadyProcessed(inspectedClass))
+        {
+            return;
+        }
+        boolean classAlreadyProcessed = false;
+
+        
         List<ResourceDependency> dependencyList = null;
         boolean isCachedList = false;
         
@@ -1985,7 +1996,6 @@ public class ApplicationImpl extends App
         {
             for (ResourceDependency dependency : dependencyList)
             {
-                RequestViewContext rvc = RequestViewContext.getCurrentInstance(context);
                 if (!rvc.isResourceDependencyAlreadyProcessed(dependency))
                 {
                     _handleResourceDependency(context, component, dependency);
@@ -1996,6 +2006,10 @@ public class ApplicationImpl extends App
         
         if(isProduction && !isCachedList)   //if we're in production and the list
is not yet cached, store it
             _classToResourceDependencyMap.put(inspectedClass, dependencyList);  //null value
stored for dependencyList means no annotations were found
+        
+        if (!classAlreadyProcessed) { 
+            rvc.setClassProcessed(inspectedClass);
+        }
     }
     
     private void _handleResourceDependency(FacesContext context, UIComponent component, ResourceDependency
annotation)

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/RequestViewContext.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/RequestViewContext.java?rev=1004881&r1=1004880&r2=1004881&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/RequestViewContext.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/RequestViewContext.java
Wed Oct  6 02:35:57 2010
@@ -36,7 +36,9 @@ public class RequestViewContext
 
     public static final String VIEW_CONTEXT_KEY = "oam.VIEW_CONTEXT";
     
-    private Map<ResourceDependency, Boolean> addedResources = new HashMap<ResourceDependency,Boolean>();

+    private Map<ResourceDependency, Boolean> addedResources = new HashMap<ResourceDependency,Boolean>();
+    
+    private Map<Class<?>, Boolean> processedClasses = new HashMap<Class<?>,Boolean>();
 
     static public RequestViewContext getCurrentInstance()
     {
@@ -83,4 +85,14 @@ public class RequestViewContext
     {
         addedResources.put(dependency, true);
     }
+
+    public boolean isClassAlreadyProcessed(Class<?> inspectedClass)
+    {
+        return processedClasses.containsKey(inspectedClass);
+    }
+
+    public void setClassProcessed(Class<?> inspectedClass)
+    {
+        processedClasses.put(inspectedClass, Boolean.TRUE);
+    }
 }



Mime
View raw message