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 2011/05/06 18:26:31 UTC
svn commit: r1100266 - in /myfaces/core/branches/2.0.x:
api/src/main/java/javax/faces/component/ api/src/main/java/javax/faces/view/
impl/src/main/java/org/apache/myfaces/renderkit/
impl/src/main/java/org/apache/myfaces/renderkit/html/ impl/src/main/ja...
Author: lu4242
Date: Fri May 6 16:26:30 2011
New Revision: 1100266
URL: http://svn.apache.org/viewvc?rev=1100266&view=rev
Log:
MYFACES-3129 [PERF] Call first getChildCount() or getFacetCount() before try to create the iterator
Modified:
myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIViewRoot.java
myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_SelectItemsIterator.java
myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/view/ViewMetadata.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlFormatRenderer.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/html/HtmlOutputScriptHandler.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/html/HtmlOutputStylesheetHandler.java
Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIViewRoot.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIViewRoot.java?rev=1100266&r1=1100265&r2=1100266&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIViewRoot.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIViewRoot.java Fri May 6 16:26:30 2011
@@ -528,8 +528,14 @@ public class UIViewRoot extends UICompon
*/
if (facet != null)
{
- List<UIComponent> children = facet.getChildren();
- return ( children == null ? Collections.<UIComponent>emptyList() : Collections.unmodifiableList(children) );
+ if (facet.getChildCount() > 0)
+ {
+ return Collections.unmodifiableList(facet.getChildren());
+ }
+ else
+ {
+ return Collections.<UIComponent>emptyList();
+ }
}
return Collections.<UIComponent>emptyList();
}
@@ -1116,9 +1122,8 @@ public class UIViewRoot extends UICompon
//Only if the facet is found it is possible to remove the resource,
//otherwise nothing should happen (call to getComponentResource trigger
//creation of facet)
- List<UIComponent> componentResources = facet.getChildren();
// Remove the component resource from the child list
- componentResources.remove(componentResource);
+ facet.getChildren().remove(componentResource);
}
}
Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_SelectItemsIterator.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_SelectItemsIterator.java?rev=1100266&r1=1100265&r2=1100266&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_SelectItemsIterator.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_SelectItemsIterator.java Fri May 6 16:26:30 2011
@@ -46,6 +46,8 @@ class _SelectItemsIterator implements It
private static final Logger log = Logger.getLogger(_SelectItemsIterator.class.getName());
+ private static final Iterator<UIComponent> _EMPTY_UICOMPONENT_ITERATOR = new _EmptyIterator<UIComponent>();
+
// org.apache.myfaces.shared.util.SelectItemsIterator uses JSFAttr
private static final String VAR_ATTR = "var";
private static final String ITEM_VALUE_ATTR = "itemValue";
@@ -63,7 +65,7 @@ class _SelectItemsIterator implements It
public _SelectItemsIterator(UIComponent selectItemsParent, FacesContext facesContext)
{
- _children = selectItemsParent.getChildren().iterator();
+ _children = selectItemsParent.getChildCount() > 0 ? selectItemsParent.getChildren().iterator() : _EMPTY_UICOMPONENT_ITERATOR;
_facesContext = facesContext;
}
Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/view/ViewMetadata.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/view/ViewMetadata.java?rev=1100266&r1=1100265&r2=1100266&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/view/ViewMetadata.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/view/ViewMetadata.java Fri May 6 16:26:30 2011
@@ -42,7 +42,7 @@ public abstract class ViewMetadata
public static Collection<UIViewParameter> getViewParameters(UIViewRoot root)
{
- LinkedList<UIViewParameter> result = new LinkedList<UIViewParameter>();
+ LinkedList<UIViewParameter> result = null;
UIComponent metadataFacet = root.getFacet (UIViewRoot.METADATA_FACET_NAME);
Iterator<UIComponent> children;
@@ -54,19 +54,33 @@ public abstract class ViewMetadata
// Iterate over all the children, keep only the view parameters.
- children = metadataFacet.getChildren().iterator();
-
- while (children.hasNext()) {
- UIComponent component = children.next();
-
- if (component instanceof UIViewParameter) {
- result.add ((UIViewParameter) component);
- }
+ if (metadataFacet.getChildCount() > 0)
+ {
+ children = metadataFacet.getChildren().iterator();
+
+ while (children.hasNext()) {
+ UIComponent component = children.next();
+
+ if (result == null)
+ {
+ result = new LinkedList<UIViewParameter>();
+ }
+
+ if (component instanceof UIViewParameter) {
+ result.add ((UIViewParameter) component);
+ }
+ }
}
// TODO: does this need to be immutable? Spec does not indicate either
// way.
-
- return Collections.unmodifiableCollection (result);
+ if (result == null)
+ {
+ return Collections.emptyList();
+ }
+ else
+ {
+ return Collections.unmodifiableCollection (result);
+ }
}
}
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java?rev=1100266&r1=1100265&r2=1100266&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java Fri May 6 16:26:30 2011
@@ -989,11 +989,14 @@ public final class ErrorPageWriter
UIComponent parent = component.getParent();
if (parent != null)
{
- for (Map.Entry<String, UIComponent> entry : parent.getFacets().entrySet())
+ if (parent.getFacetCount() > 0)
{
- if (entry.getValue() == component)
+ for (Map.Entry<String, UIComponent> entry : parent.getFacets().entrySet())
{
- return entry.getKey();
+ if (entry.getValue() == component)
+ {
+ return entry.getKey();
+ }
}
}
}
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlFormatRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlFormatRenderer.java?rev=1100266&r1=1100265&r2=1100266&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlFormatRenderer.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlFormatRenderer.java Fri May 6 16:26:30 2011
@@ -90,16 +90,30 @@ public class HtmlFormatRenderer extends
}
else
{
- List<Object> argsList = new ArrayList<Object>();
+ List<Object> argsList = null;
- List<UIParameter> validParams = HtmlRendererUtils.getValidUIParameterChildren(
- facesContext, htmlOutputFormat.getChildren(), false, false, false);
- for (UIParameter param : validParams)
+ if (htmlOutputFormat.getChildCount() > 0)
{
- argsList.add(param.getValue());
+ List<UIParameter> validParams = HtmlRendererUtils.getValidUIParameterChildren(
+ facesContext, htmlOutputFormat.getChildren(), false, false, false);
+ for (UIParameter param : validParams)
+ {
+ if (argsList == null)
+ {
+ argsList = new ArrayList<Object>();
+ }
+ argsList.add(param.getValue());
+ }
}
- args = argsList.toArray(new Object[argsList.size()]);
+ if (argsList != null)
+ {
+ args = argsList.toArray(new Object[argsList.size()]);
+ }
+ else
+ {
+ args = EMPTY_ARGS;
+ }
}
MessageFormat format = new MessageFormat(pattern, facesContext.getViewRoot().getLocale());
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java?rev=1100266&r1=1100265&r2=1100266&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java Fri May 6 16:26:30 2011
@@ -251,12 +251,15 @@ public class DefaultFaceletsStateManagem
if (!target.getParent().getChildren().remove(target))
{
String key = null;
- for (Map.Entry<String, UIComponent> entry : target.getParent().getFacets().entrySet())
+ if (target.getParent().getFacetCount() > 0)
{
- if (entry.getValue()==target)
+ for (Map.Entry<String, UIComponent> entry : target.getParent().getFacets().entrySet())
{
- key = entry.getKey();
- break;
+ if (entry.getValue()==target)
+ {
+ key = entry.getKey();
+ break;
+ }
}
}
if (key != null)
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java?rev=1100266&r1=1100265&r2=1100266&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java Fri May 6 16:26:30 2011
@@ -521,13 +521,16 @@ public class FaceletCompositionContextIm
else if (Boolean.TRUE.equals(fc.getAttributes().get(ComponentSupport.FACET_CREATED_UIPANEL_MARKER)))
{
//Mark its children, but do not mark itself.
- for (Iterator<UIComponent> fciter = fc.getChildren().iterator(); fciter.hasNext();)
+ if (fc.getChildCount() > 0)
{
- UIComponent child = fciter.next();
- id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
- if (id != null)
+ for (Iterator<UIComponent> fciter = fc.getChildren().iterator(); fciter.hasNext();)
{
- markComponentForDeletion(id, child);
+ UIComponent child = fciter.next();
+ id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
+ if (id != null)
+ {
+ markComponentForDeletion(id, child);
+ }
}
}
}
@@ -583,13 +586,16 @@ public class FaceletCompositionContextIm
}
else if ( id == null && Boolean.TRUE.equals(fc.getAttributes().get(ComponentSupport.FACET_CREATED_UIPANEL_MARKER)))
{
- for (Iterator<UIComponent> fciter = fc.getChildren().iterator(); fciter.hasNext();)
+ if (fc.getChildCount() > 0)
{
- UIComponent child = fciter.next();
- id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
- if (id != null && removeComponentForDeletion(id) != null)
+ for (Iterator<UIComponent> fciter = fc.getChildren().iterator(); fciter.hasNext();)
{
- fciter.remove();
+ UIComponent child = fciter.next();
+ id = (String) child.getAttributes().get(ComponentSupport.MARK_CREATED);
+ if (id != null && removeComponentForDeletion(id) != null)
+ {
+ fciter.remove();
+ }
}
}
if (fc.getChildCount() == 0)
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java?rev=1100266&r1=1100265&r2=1100266&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java Fri May 6 16:26:30 2011
@@ -132,37 +132,44 @@ public final class ComponentSupport
*/
public static UIComponent findChildByTagId(UIComponent parent, String id)
{
- Iterator<UIComponent> itr = parent.getChildren().iterator();
- while (itr.hasNext())
+ Iterator<UIComponent> itr = null;
+ if (parent.getChildCount() > 0)
{
- UIComponent child = itr.next();
- if (id.equals(child.getAttributes().get(MARK_CREATED)))
+ itr = parent.getChildren().iterator();
+ while (itr.hasNext())
{
- return child;
+ UIComponent child = itr.next();
+ if (id.equals(child.getAttributes().get(MARK_CREATED)))
+ {
+ return child;
+ }
}
}
- itr = parent.getFacets().values().iterator();
- while (itr.hasNext())
+ if (parent.getFacetCount() > 0)
{
- UIComponent facet = itr.next();
- // check if this is a dynamically generated UIPanel
- if (Boolean.TRUE.equals(facet.getAttributes()
- .get(FACET_CREATED_UIPANEL_MARKER)))
+ itr = parent.getFacets().values().iterator();
+ while (itr.hasNext())
{
- // only check the children and facets of the panel
- Iterator<UIComponent> itr2 = facet.getFacetsAndChildren();
- while (itr2.hasNext())
+ UIComponent facet = itr.next();
+ // check if this is a dynamically generated UIPanel
+ if (Boolean.TRUE.equals(facet.getAttributes()
+ .get(FACET_CREATED_UIPANEL_MARKER)))
{
- UIComponent child = itr2.next();
- if (id.equals(child.getAttributes().get(MARK_CREATED)))
+ // only check the children and facets of the panel
+ Iterator<UIComponent> itr2 = facet.getFacetsAndChildren();
+ while (itr2.hasNext())
{
- return child;
+ UIComponent child = itr2.next();
+ if (id.equals(child.getAttributes().get(MARK_CREATED)))
+ {
+ return child;
+ }
}
}
- }
- else if (id.equals(facet.getAttributes().get(MARK_CREATED)))
- {
- return facet;
+ else if (id.equals(facet.getAttributes().get(MARK_CREATED)))
+ {
+ return facet;
+ }
}
}
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/html/HtmlOutputScriptHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/html/HtmlOutputScriptHandler.java?rev=1100266&r1=1100265&r2=1100266&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/html/HtmlOutputScriptHandler.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/html/HtmlOutputScriptHandler.java Fri May 6 16:26:30 2011
@@ -54,11 +54,15 @@ public class HtmlOutputScriptHandler ext
if (c == null)
{
UIViewRoot root = ComponentSupport.getViewRoot(ctx, parent);
- Iterator<UIComponent> itr = root.getFacets().values().iterator();
- while (itr.hasNext() && c == null)
+
+ if (root.getFacetCount() > 0)
{
- UIComponent facet = itr.next();
- c = ComponentSupport.findChildByTagId(facet, id);
+ Iterator<UIComponent> itr = root.getFacets().values().iterator();
+ while (itr.hasNext() && c == null)
+ {
+ UIComponent facet = itr.next();
+ c = ComponentSupport.findChildByTagId(facet, id);
+ }
}
return c;
}
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/html/HtmlOutputStylesheetHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/html/HtmlOutputStylesheetHandler.java?rev=1100266&r1=1100265&r2=1100266&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/html/HtmlOutputStylesheetHandler.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/html/HtmlOutputStylesheetHandler.java Fri May 6 16:26:30 2011
@@ -51,11 +51,14 @@ public class HtmlOutputStylesheetHandler
{
UIComponent c = null;
UIViewRoot root = ComponentSupport.getViewRoot(ctx, parent);
- Iterator<UIComponent> itr = root.getFacets().values().iterator();
- while (itr.hasNext() && c == null)
+ if (root.getFacetCount() > 0)
{
- UIComponent facet = itr.next();
- c = ComponentSupport.findChildByTagId(facet, id);
+ Iterator<UIComponent> itr = root.getFacets().values().iterator();
+ while (itr.hasNext() && c == null)
+ {
+ UIComponent facet = itr.next();
+ c = ComponentSupport.findChildByTagId(facet, id);
+ }
}
return c;
}