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 2013/04/23 03:07:54 UTC

svn commit: r1470769 - in /myfaces/core/branches/2.1.x: api/src/main/java/javax/faces/component/ impl/src/main/java/org/apache/myfaces/application/ impl/src/main/java/org/apache/myfaces/renderkit/ impl/src/main/java/org/apache/myfaces/util/ impl/src/ma...

Author: lu4242
Date: Tue Apr 23 01:07:54 2013
New Revision: 1470769

URL: http://svn.apache.org/r1470769
Log:
MYFACES-3713 [perf] use getFacetCount() when possible and avoid create iterator instances 

Modified:
    myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UIComponent.java
    myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UIComponentBase.java
    myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UIData.java
    myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/application/TreeStructureManager.java
    myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java
    myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/util/DebugUtils.java
    myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java

Modified: myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UIComponent.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UIComponent.java?rev=1470769&r1=1470768&r2=1470769&view=diff
==============================================================================
--- myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UIComponent.java (original)
+++ myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UIComponent.java Tue Apr 23 01:07:54 2013
@@ -233,9 +233,23 @@ public abstract class UIComponent
                 return found;
             }
             // Searching for this component's children/facets
-            for (Iterator<UIComponent> it = this.getFacetsAndChildren(); !found && it.hasNext(); )
+            // [perf] Use getFacetsAndChildren() is nicer but this one prevents
+            // create 1 iterator per component class that does not have
+            // facets attached, which is a common case. 
+            if (this.getFacetCount() > 0)
             {
-                found = it.next().invokeOnComponent(context, clientId, callback);
+                for (Iterator<UIComponent> it = this.getFacets().values().iterator(); !found && it.hasNext(); )
+                {
+                    found = it.next().invokeOnComponent(context, clientId, callback);
+                }                
+            }
+            if (this.getChildCount() > 0)
+            {
+                for (int i = 0, childCount = getChildCount(); !found && (i < childCount); i++)
+                {
+                    UIComponent child = getChildren().get(i);
+                    found = child.invokeOnComponent(context, clientId, callback);
+                }
             }
             return found;
         }

Modified: myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UIComponentBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UIComponentBase.java?rev=1470769&r1=1470768&r2=1470769&view=diff
==============================================================================
--- myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UIComponentBase.java (original)
+++ myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UIComponentBase.java Tue Apr 23 01:07:54 2013
@@ -1149,8 +1149,6 @@ public abstract class UIComponentBase ex
             }
         }
     }
-    
-    
 
     @Override
     public boolean visitTree(VisitContext context, VisitCallback callback)

Modified: myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UIData.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UIData.java?rev=1470769&r1=1470768&r2=1470769&view=diff
==============================================================================
--- myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UIData.java (original)
+++ myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UIData.java Tue Apr 23 01:07:54 2013
@@ -423,11 +423,16 @@ public class UIData extends UIComponentB
                             returnValue = true;
                         }
                         // process the child's facets
-                        for (Iterator<UIComponent> itChildFacets = child.getFacets().values().iterator(); 
-                                !returnValue && itChildFacets.hasNext();)
+                        if (child.getFacetCount() > 0)
                         {
-                            //recursive call to find the component
-                            returnValue = itChildFacets.next().invokeOnComponent(context, clientId, callback);
+                            for (Iterator<UIComponent> itChildFacets = 
+                                child.getFacets().values().iterator(); 
+                                !returnValue && itChildFacets.hasNext();)
+                            {
+                                //recursive call to find the component
+                                returnValue = itChildFacets.next().invokeOnComponent(
+                                    context, clientId, callback);
+                            }
                         }
                     }
                 }
@@ -2190,11 +2195,14 @@ public class UIData extends UIComponentB
                                 {
                                     return true;
                                 }
-                                for (UIComponent facet : child.getFacets().values())
+                                if (child.getFacetCount() > 0)
                                 {
-                                    if (facet.visitTree(context, callback))
+                                    for (UIComponent facet : child.getFacets().values())
                                     {
-                                        return true;
+                                        if (facet.visitTree(context, callback))
+                                        {
+                                            return true;
+                                        }
                                     }
                                 }
                             }

Modified: myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/application/TreeStructureManager.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/application/TreeStructureManager.java?rev=1470769&r1=1470768&r2=1470769&view=diff
==============================================================================
--- myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/application/TreeStructureManager.java (original)
+++ myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/application/TreeStructureManager.java Tue Apr 23 01:07:54 2013
@@ -73,9 +73,10 @@ public class TreeStructureManager
         }
 
         //facets
-        Map<String, UIComponent> facetMap = component.getFacets();
-        if (!facetMap.isEmpty())
+        
+        if (component.getFacetCount() > 0)
         {
+            Map<String, UIComponent> facetMap = component.getFacets();
             List<Object[]> structFacetList = new ArrayList<Object[]>();
             for (Map.Entry<String, UIComponent> entry : facetMap.entrySet())
             {

Modified: myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java?rev=1470769&r1=1470768&r2=1470769&view=diff
==============================================================================
--- myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java (original)
+++ myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java Tue Apr 23 01:07:54 2013
@@ -839,7 +839,7 @@ public final class ErrorPageWriter
         }
         writer.write(">");
 
-        boolean hasChildren = (c.getChildCount() > 0 || c.getFacets().size() > 0) && writeChildren;
+        boolean hasChildren = (c.getChildCount() > 0 || c.getFacetCount() > 0) && writeChildren;
 
         int stateSize = 0;
 
@@ -865,7 +865,7 @@ public final class ErrorPageWriter
         writer.write("</dt>");
         if (hasChildren)
         {
-            if (c.getFacets().size() > 0)
+            if (c.getFacetCount() > 0)
             {
                 for (Map.Entry<String, UIComponent> entry : c.getFacets().entrySet())
                 {
@@ -939,7 +939,7 @@ public final class ErrorPageWriter
                 }
 
                 UIComponent parent = target.getParent();
-                boolean hasChildren = (target.getChildCount() > 0 || target.getFacets().size() > 0);
+                boolean hasChildren = (target.getChildCount() > 0 || target.getFacetCount() > 0);
                 String facetName = _getFacetName(target);
 
                 if (!(target instanceof UIColumn))

Modified: myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/util/DebugUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/util/DebugUtils.java?rev=1470769&r1=1470768&r2=1470769&view=diff
==============================================================================
--- myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/util/DebugUtils.java (original)
+++ myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/util/DebugUtils.java Tue Apr 23 01:07:54 2013
@@ -298,9 +298,9 @@ public class DebugUtils
         if (withChildrenAndFacets)
         {
             int childCount = comp.getChildCount();
-            Map<String, UIComponent> facetsMap = comp.getFacets();
-            if (childCount > 0 || !facetsMap.isEmpty())
+            if (childCount > 0 || comp.getFacetCount() > 0)
             {
+                Map<String, UIComponent> facetsMap = comp.getFacets();
                 nestedObjects = true;
                 if (mustClose)
                 {

Modified: myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java?rev=1470769&r1=1470768&r2=1470769&view=diff
==============================================================================
--- myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java (original)
+++ myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java Tue Apr 23 01:07:54 2013
@@ -99,9 +99,9 @@ public final class ComponentSupport
         }
 
         // remove any facets marked as deleted
-        Map<String, UIComponent> facets = component.getFacets();
-        if (!facets.isEmpty())
+        if (component.getFacetCount() > 0)
         {
+            Map<String, UIComponent> facets = component.getFacets();
             Collection<UIComponent> col = facets.values();
             for (Iterator<UIComponent> itr = col.iterator(); itr.hasNext();)
             {
@@ -346,9 +346,9 @@ public final class ComponentSupport
             }
         }
         
-        Map<String, UIComponent> facets = component.getFacets();
-        if (!facets.isEmpty())
+        if (component.getFacetCount() > 0)
         {
+            Map<String, UIComponent> facets = component.getFacets();
             for (Iterator<UIComponent> itr = facets.values().iterator(); itr.hasNext();)
             {
                 UIComponent facet = itr.next();