You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/10/06 04:34:46 UTC

svn commit: r1004880 - /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java

Author: lu4242
Date: Wed Oct  6 02:34:46 2010
New Revision: 1004880

URL: http://svn.apache.org/viewvc?rev=1004880&view=rev
Log:
MYFACES-2862 [PERF] Improve efficiency of Application.createComponent(FacesContext,Resource) in production (Thanks to Martin Koci for this patch)

Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.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=1004880&r1=1004879&r2=1004880&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:34:46 2010
@@ -56,6 +56,7 @@ import javax.faces.application.ResourceH
 import javax.faces.application.StateManager;
 import javax.faces.application.ViewHandler;
 import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
 import javax.faces.component.UINamingContainer;
 import javax.faces.component.UIOutput;
 import javax.faces.component.UIViewRoot;
@@ -199,6 +200,18 @@ public class ApplicationImpl extends App
     private List<Class<? extends Converter>> _noArgConstructorConverterClasses 
             = new ArrayList<Class<? extends Converter>>();
     
+    /**
+     * Represents semantic null in _componentClassMap. 
+     */
+    private static final UIComponent NOTHING = new UIComponentBase()
+    {
+        @Override
+        public String getFamily()
+        {
+            return null;
+        }
+    };
+    
     // ~ Constructors
     // --------------------------------------------------------------------------
     // -----
@@ -1186,20 +1199,32 @@ public class ApplicationImpl extends App
                  * re-throw it. If any other exception is thrown, log the exception and continue to the next step.
                  */
 
+                boolean isProduction = FacesContext.getCurrentInstance().isProjectStage(ProjectStage.Production);
                 String name = componentResource.getResourceName();
                 String className = name.substring(0, name.lastIndexOf('.'));
                 fqcn = componentResource.getLibraryName() + "." + className;
-
-                try
-                {
-                    componentClass = ClassUtils.classForName(fqcn);
+                
+                if (isProduction) {
+                    componentClass = (Class<? extends UIComponent>) _componentClassMap.get(fqcn);
                 }
-                catch (ClassNotFoundException e)
-                {
+                if (componentClass == null) {
+                    try
+                    {
+                        componentClass = ClassUtils.classForName(fqcn);
+                        if (isProduction) {
+                            _componentClassMap.put(fqcn, componentClass);
+                        }
+                    }
+                    catch (ClassNotFoundException e)
+                    {
+                        // Remember here that classForName did not find Class
+                        if (isProduction) {
+                            _componentClassMap.put(fqcn, NOTHING.getClass());
+                        }
+                    }
                 }
 
-                if (componentClass != null)
-                {
+                if (componentClass != null && NOTHING.getClass() != componentClass)                {
                     try
                     {
                         component = componentClass.newInstance();