myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1100265 - in /myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared: renderkit/html/HtmlRendererUtils.java util/SelectItemsIterator.java util/_EmptyIterator.java
Date Fri, 06 May 2011 16:26:30 GMT
Author: lu4242
Date: Fri May  6 16:26:29 2011
New Revision: 1100265

URL: http://svn.apache.org/viewvc?rev=1100265&view=rev
Log:
MYFACES-3129 [PERF] Call first getChildCount() or getFacetCount() before try to create the
iterator

Added:
    myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_EmptyIterator.java
Modified:
    myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
    myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/SelectItemsIterator.java

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java?rev=1100265&r1=1100264&r2=1100265&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
(original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
Fri May  6 16:26:29 2011
@@ -1798,27 +1798,40 @@ public final class HtmlRendererUtils {
             return null;
         }
 
+        Map<String, List<String>> parameters = null;
         // handle URL parameters
-        Map<String, List<String>> parameters = new HashMap<String, List<String>>();
-        List<UIParameter> validParams = getValidUIParameterChildren(
-                facesContext, component.getChildren(), true, false);
-        for (UIParameter param : validParams) {
-            String name = param.getName();
-            Object value = param.getValue();
-            if (parameters.containsKey(name)) {
-                parameters.get(name).add(value.toString());
-            } else {
-                List<String> list = new ArrayList<String>(1);
-                list.add(value.toString());
-                parameters.put(name, list);
+        if (component.getChildCount() > 0)
+        {
+            parameters = new HashMap<String, List<String>>();
+            List<UIParameter> validParams = getValidUIParameterChildren(
+                    facesContext, component.getChildren(), true, false);
+            for (UIParameter param : validParams) {
+                String name = param.getName();
+                Object value = param.getValue();
+                if (parameters.containsKey(name)) {
+                    parameters.get(name).add(value.toString());
+                } else {
+                    List<String> list = new ArrayList<String>(1);
+                    list.add(value.toString());
+                    parameters.put(name, list);
+                }
             }
         }
 
         // handle NavigationCase parameters
         Map<String, List<String>> navigationCaseParams = navigationCase.getParameters();
         if (navigationCaseParams != null) {
+            if (parameters == null)
+            {
+                parameters = new HashMap<String, List<String>>(); 
+            }
             parameters.putAll(navigationCaseParams);
         }
+        
+        if (parameters == null)
+        {
+            parameters = Collections.emptyMap();
+        }
 
         // In theory the precedence order to deal with params is this:
         // component parameters, navigation-case parameters, view parameters
@@ -2326,22 +2339,34 @@ public final class HtmlRendererUtils {
      * @return
      */
     public static Map<String, String> mapAttachedParamsToStringValues(FacesContext
facesContext, UIComponent uiComponent) {
-        Map<String, String> retVal = new HashMap<String, String>();
+        Map<String, String> retVal = null;
 
-        List<UIParameter> validParams = getValidUIParameterChildren(
-                facesContext, uiComponent.getChildren(), true, true);
-        for (UIParameter param : validParams) {
-            String name = param.getName();
-            Object value = param.getValue();
-            if (value instanceof String)
-            {
-                retVal.put(name, (String) value);
-            }
-            else
-            {
-                retVal.put(name, value.toString());
+        if (uiComponent.getChildCount() > 0)
+        {
+            List<UIParameter> validParams = getValidUIParameterChildren(
+                    facesContext, uiComponent.getChildren(), true, true);
+            for (UIParameter param : validParams) {
+                String name = param.getName();
+                Object value = param.getValue();
+                if (retVal == null)
+                {
+                    retVal = new HashMap<String, String>();
+                }
+                if (value instanceof String)
+                {
+                    retVal.put(name, (String) value);
+                }
+                else
+                {
+                    retVal.put(name, value.toString());
+                }
             }
         }
+        
+        if (retVal == null)
+        {
+            retVal = Collections.emptyMap();
+        }
 
         return retVal;
     }

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/SelectItemsIterator.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/SelectItemsIterator.java?rev=1100265&r1=1100264&r2=1100265&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/SelectItemsIterator.java
(original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/SelectItemsIterator.java
Fri May  6 16:26:29 2011
@@ -59,6 +59,8 @@ public class SelectItemsIterator impleme
     private static final String ITEM_LABEL_ESCAPED_ATTR = JSFAttr.ITEM_LABEL_ESCAPED_ATTR;
     private static final String NO_SELECTION_VALUE_ATTR = JSFAttr.NO_SELECTION_VALUE_ATTR;
     
+    private static final Iterator<UIComponent> _EMPTY_UICOMPONENT_ITERATOR = new _EmptyIterator<UIComponent>();
+    
     private final Iterator<UIComponent> _children;
     private Iterator<? extends Object> _nestedItems;
     private SelectItem _nextItem;
@@ -67,7 +69,7 @@ public class SelectItemsIterator impleme
 
     public SelectItemsIterator(UIComponent selectItemsParent, FacesContext facesContext)
     {
-        _children = selectItemsParent.getChildren().iterator();
+        _children = selectItemsParent.getChildCount() > 0 ? selectItemsParent.getChildren().iterator()
: _EMPTY_UICOMPONENT_ITERATOR; 
         _facesContext = facesContext;
     }
 

Added: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_EmptyIterator.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_EmptyIterator.java?rev=1100265&view=auto
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_EmptyIterator.java
(added)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/_EmptyIterator.java
Fri May  6 16:26:29 2011
@@ -0,0 +1,41 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.myfaces.shared.util;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+class _EmptyIterator<T> implements Iterator<T>
+{
+
+    public boolean hasNext()
+    {
+        return false;
+    }
+
+    public T next()
+    {
+        throw new NoSuchElementException();
+    }
+
+    public void remove()
+    {
+        throw new UnsupportedOperationException();
+    }
+}



Mime
View raw message