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 2012/03/02 19:27:54 UTC

svn commit: r1296362 - in /myfaces/core/branches/2.0.x: api/src/main/java/javax/faces/component/ impl/src/main/java/org/apache/myfaces/component/visit/ impl/src/main/java/org/apache/myfaces/lifecycle/ impl/src/main/java/org/apache/myfaces/renderkit/htm...

Author: lu4242
Date: Fri Mar  2 18:27:53 2012
New Revision: 1296362

URL: http://svn.apache.org/viewvc?rev=1296362&view=rev
Log:
MYFACES-3467 [PERF] Use index-based loop where possible - part II (Thanks to Martin Koci for provide this patch)

Modified:
    myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIComponentBase.java
    myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIData.java
    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/_ComponentChildrenList.java
    myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_DeltaList.java
    myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/component/visit/PartialVisitContext.java
    myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/lifecycle/RenderResponseExecutor.java
    myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlAjaxBehaviorRenderer.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/FaceletViewDeclarationLanguage.java
    myfaces/core/branches/2.0.x/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
    myfaces/core/branches/2.0.x/shared/src/main/java/org/apache/myfaces/shared/util/ArrayUtils.java

Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIComponentBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIComponentBase.java?rev=1296362&r1=1296361&r2=1296362&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIComponentBase.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIComponentBase.java Fri Mar  2 18:27:53 2012
@@ -401,9 +401,10 @@ public abstract class UIComponentBase ex
             {
                 return;
             }
-            for (Iterator<FacesListener> it = _facesListeners.iterator(); it.hasNext();)
+            // perf: _facesListeners is RandomAccess instance (javax.faces.component._DeltaList)
+            for (int i = 0, size = _facesListeners.size(); i < size; i++)
             {
-                FacesListener facesListener = it.next();
+                FacesListener facesListener = _facesListeners.get(i);
                 if (event.isAppropriateListener(facesListener))
                 {
                     event.processListener(facesListener);
@@ -1164,9 +1165,10 @@ public abstract class UIComponentBase ex
             return (FacesListener[]) Array.newInstance(clazz, 0);
         }
         List<FacesListener> lst = null;
-        for (Iterator<FacesListener> it = _facesListeners.iterator(); it.hasNext();)
+        // perf: _facesListeners is RandomAccess instance (javax.faces.component._DeltaList)
+        for (int i = 0, size = _facesListeners.size(); i < size; i++)
         {
-            FacesListener facesListener = it.next();
+            FacesListener facesListener = _facesListeners.get(i);
             if (facesListener != null && clazz.isAssignableFrom(facesListener.getClass()))
             {
                 if (lst == null)
@@ -1670,9 +1672,12 @@ public abstract class UIComponentBase ex
         {
             if (ArrayList.class.equals(attachedObject.getClass()))
             {
-                List<Object> lst = new ArrayList<Object>(((List<?>) attachedObject).size());
-                for (Object item : (List<?>) attachedObject)
+                ArrayList<?> list = (ArrayList<?>) attachedObject;
+                int size = list.size();
+                List<Object> lst = new ArrayList<Object>(size);
+                for (int i = 0; i < size; i++)
                 {
+                    Object item = list.get(i);
                     if (item != null)
                     {
                         lst.add(saveAttachedState(context, item));
@@ -1715,10 +1720,12 @@ public abstract class UIComponentBase ex
         }
         if (stateObj instanceof _AttachedListStateWrapper)
         {
-            List<Object> lst = ((_AttachedListStateWrapper) stateObj).getWrappedStateList();
+            // perf: getWrappedStateList in _AttachedListStateWrapper is always ArrayList: see saveAttachedState
+            ArrayList<Object> lst = (ArrayList<Object>) ((_AttachedListStateWrapper) stateObj).getWrappedStateList();
             List<Object> restoredList = new ArrayList<Object>(lst.size());
-            for (Object item : lst)
+            for (int i = 0, size = lst.size(); i < size; i++)
             {
+                Object item = lst.get(i);
                 restoredList.add(restoreAttachedState(context, item));
             }
             return restoredList;

Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIData.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIData.java?rev=1296362&r1=1296361&r2=1296362&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIData.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIData.java Fri Mar  2 18:27:53 2012
@@ -1104,9 +1104,12 @@ public class UIData extends UIComponentB
 
     private boolean hasErrorMessages(FacesContext context)
     {
-        for (Iterator<FacesMessage> iter = context.getMessages(); iter.hasNext();)
+        // perf: getMessageList() return a RandomAccess instance.
+        // See org.apache.myfaces.context.servlet.FacesContextImpl.addMessage
+        List<FacesMessage> messageList = context.getMessageList();
+        for (int i = 0, size = messageList.size(); i < size;  i++)
         {
-            FacesMessage message = iter.next();
+            FacesMessage message = messageList.get(i);
             if (FacesMessage.SEVERITY_ERROR.compareTo(message.getSeverity()) <= 0)
             {
                 return true;

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=1296362&r1=1296361&r2=1296362&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 Mar  2 18:27:53 2012
@@ -1357,22 +1357,26 @@ public class UIViewRoot extends UICompon
     private Events _getEvents(PhaseId phaseId)
     {
         // Gather the events and purge the event list to prevent concurrent modification during broadcasting
-        List<FacesEvent> anyPhase = new ArrayList<FacesEvent>(
-                _events.size());
-        List<FacesEvent> onPhase = new ArrayList<FacesEvent>(_events.size());
-        for (Iterator<FacesEvent> iterator = _events.iterator(); iterator
-                .hasNext();)
+        int size = _events.size();
+        List<FacesEvent> anyPhase = new ArrayList<FacesEvent>(size);
+        List<FacesEvent> onPhase = new ArrayList<FacesEvent>(size);
+        
+        for (int i = 0; i < size; i++)
         {
-            FacesEvent event = iterator.next();
+            FacesEvent event = _events.get(i);
             if (event.getPhaseId().equals(PhaseId.ANY_PHASE))
             {
                 anyPhase.add(event);
-                iterator.remove();
+                _events.remove(i);
+                size--;
+                i--;
             }
             else if (event.getPhaseId().equals(phaseId))
             {
                 onPhase.add(event);
-                iterator.remove();
+                _events.remove(i);
+                size--;
+                i--;
             }
         }
         

Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_ComponentChildrenList.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_ComponentChildrenList.java?rev=1296362&r1=1296361&r2=1296362&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_ComponentChildrenList.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_ComponentChildrenList.java Fri Mar  2 18:27:53 2012
@@ -24,12 +24,13 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.RandomAccess;
 
 /**
  * @author Manfred Geiler (latest modification by $Author$)
  * @version $Revision$ $Date$
  */
-class _ComponentChildrenList extends AbstractList<UIComponent> implements Serializable
+class _ComponentChildrenList extends AbstractList<UIComponent> implements Serializable, RandomAccess
 {
     private static final long serialVersionUID = -6775078929331154224L;
     private UIComponent _component;

Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_DeltaList.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_DeltaList.java?rev=1296362&r1=1296361&r2=1296362&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_DeltaList.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_DeltaList.java Fri Mar  2 18:27:53 2012
@@ -23,6 +23,7 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.ListIterator;
+import java.util.RandomAccess;
 
 import javax.faces.context.FacesContext;
 
@@ -42,7 +43,7 @@ import javax.faces.context.FacesContext;
  * @author Leonardo Uribe (latest modification by $Author$)
  * @version $Revision$ $Date$
  */
-class _DeltaList<T> implements List<T>, PartialStateHolder
+class _DeltaList<T> implements List<T>, PartialStateHolder, RandomAccess
 {
 
     private List<T> _delegate;

Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/component/visit/PartialVisitContext.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/component/visit/PartialVisitContext.java?rev=1296362&r1=1296361&r2=1296362&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/component/visit/PartialVisitContext.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/component/visit/PartialVisitContext.java Fri Mar  2 18:27:53 2012
@@ -77,14 +77,16 @@ public class PartialVisitContext extends
                              Set<VisitHint> hints)
   {
     if (facesContext == null)
-      throw new NullPointerException();
+    {
+        throw new NullPointerException();
+    }
 
     _facesContext = facesContext;
 
     // Copy the client ids into a HashSet to allow for quick lookups.
-    Set<String> clientIdSet = (clientIds == null)
-                                ? new HashSet<String>()
-                                : new HashSet<String>(clientIds);
+//    Set<String> clientIdSet = (clientIds == null)
+//            ? new HashSet<String>()
+//                    : new HashSet<String>(clientIds);
 
     // Initialize our various collections
     // We maintain 4 collections:
@@ -120,8 +122,9 @@ public class PartialVisitContext extends
     _clientIds = new CollectionProxy<String>(new HashSet<String>());
 
     // Finally, populate the clientIds collection.  This has the
-    // side effect of populating all of the other collections.       
-    _clientIds.addAll(clientIdSet);
+    // side effect of populating all of the other collections.
+    org.apache.myfaces.shared.util.ArrayUtils.addAll(_clientIds, clientIds);
+    //_clientIds.addAll(clientIdSet);
 
     // Copy and store hints - ensure unmodifiable and non-empty
     EnumSet<VisitHint> hintsEnumSet = ((hints == null) || (hints.isEmpty()))
@@ -177,9 +180,13 @@ public class PartialVisitContext extends
     Collection<String> ids = _subtreeClientIds.get(clientId);
 
     if (ids == null)
-      return Collections.emptyList();
+    {
+        return Collections.emptyList();
+    }
     else
-      return Collections.unmodifiableCollection(ids);     
+    {
+        return Collections.unmodifiableCollection(ids);
+    }
   }
 
   /**
@@ -212,7 +219,9 @@ public class PartialVisitContext extends
     // If the unvisited collection is now empty, we are done.
     // Return VisitResult.COMPLETE to terminate the visit.
     if (_unvisitedClientIds.isEmpty())
-      return VisitResult.COMPLETE;
+    {
+        return VisitResult.COMPLETE;
+    }
     else
     {
       // Otherwise, just return the callback's result 
@@ -265,9 +274,11 @@ public class PartialVisitContext extends
     String id = component.getId();
 
     if ((id != null) && !_ids.contains(id))
-      return null;
+    {
+        return null;
+    }
 
-    // The id was a match - now check the client id.
+      // The id was a match - now check the client id.
     // note that client id should never be null (should be
     // generated even if id is null, so asserting this.)
     String clientId = component.getClientId(getFacesContext());
@@ -458,4 +469,4 @@ public class PartialVisitContext extends
 
   // Our visit hints
   private final Set<VisitHint> _hints;
-}
\ No newline at end of file
+}

Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/lifecycle/RenderResponseExecutor.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/lifecycle/RenderResponseExecutor.java?rev=1296362&r1=1296361&r2=1296362&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/lifecycle/RenderResponseExecutor.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/lifecycle/RenderResponseExecutor.java Fri Mar  2 18:27:53 2012
@@ -19,6 +19,7 @@
 package org.apache.myfaces.lifecycle;
 
 import java.io.IOException;
+import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -115,12 +116,17 @@ class RenderResponseExecutor extends Pha
             viewHandler.renderView(facesContext, root);
             
             // log all unhandled FacesMessages, don't swallow them
-            if (!facesContext.getMessageList().isEmpty())
+            // perf: org.apache.myfaces.context.servlet.FacesContextImpl.getMessageList() creates
+            // new Collections.unmodifiableList with every invocation->  call it only once
+            // and messageList is RandomAccess -> use index based loop
+            List<FacesMessage> messageList = facesContext.getMessageList();
+            if (!messageList.isEmpty())
             {
                 StringBuilder builder = new StringBuilder();
                 boolean shouldLog = false;
-                for (FacesMessage message : facesContext.getMessageList())
+                for (int i = 0, size = messageList.size(); i < size; i++)
                 {
+                    FacesMessage message = messageList.get(i);
                     if (!message.isRendered())
                     {
                         builder.append("\n- ");

Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlAjaxBehaviorRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlAjaxBehaviorRenderer.java?rev=1296362&r1=1296361&r2=1296362&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlAjaxBehaviorRenderer.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlAjaxBehaviorRenderer.java Fri Mar  2 18:27:53 2012
@@ -248,22 +248,23 @@ public class HtmlAjaxBehaviorRenderer ex
              * see ClientBehaviorContext.html of the spec
              * the param list has to be added in the post back
              */
-            for (ClientBehaviorContext.Parameter param : params)
+            // params are in 99% RamdonAccess instace created in 
+            // HtmlRendererUtils.getClientBehaviorContextParameters(Map<String, String>)
+            if (params instanceof RandomAccess)
             {
-                //TODO we may need a proper type handling in this part
-                //lets leave it for now as it is
-                //quotes etc.. should be transferred directly
-                //and the rest is up to the toString properly implemented
-                //ANS: Both name and value should be quoted
-                paramBuffer.setLength(0);
-                paramBuffer.append(QUOTE);
-                paramBuffer.append(param.getName());
-                paramBuffer.append(QUOTE);
-                paramBuffer.append(COLON);
-                paramBuffer.append(QUOTE);
-                paramBuffer.append(param.getValue().toString());
-                paramBuffer.append(QUOTE);
-                parameterList.add(paramBuffer.toString());
+                List<ClientBehaviorContext.Parameter> list = (List<ClientBehaviorContext.Parameter>) params;
+                for (int i = 0, size = list.size(); i < size; i++)
+                {
+                    ClientBehaviorContext.Parameter param = list.get(i);
+                    append(paramBuffer, parameterList, param);
+                }
+            }
+            else
+            {
+                for (ClientBehaviorContext.Parameter param : params)
+                {
+                    append(paramBuffer, parameterList, param);
+                }
             }
         }
 
@@ -290,6 +291,24 @@ public class HtmlAjaxBehaviorRenderer ex
         return retVal;
     }
 
+    private void append(StringBuilder paramBuffer, List<String> parameterList, ClientBehaviorContext.Parameter param)
+    {
+        //TODO we may need a proper type handling in this part
+        //lets leave it for now as it is
+        //quotes etc.. should be transferred directly
+        //and the rest is up to the toString properly implemented
+        //ANS: Both name and value should be quoted
+        paramBuffer.setLength(0);
+        paramBuffer.append(QUOTE);
+        paramBuffer.append(param.getName());
+        paramBuffer.append(QUOTE);
+        paramBuffer.append(COLON);
+        paramBuffer.append(QUOTE);
+        paramBuffer.append(param.getValue().toString());
+        paramBuffer.append(QUOTE);
+        parameterList.add(paramBuffer.toString());
+    }
+
 
     private StringBuilder buildOptions(FacesContext facesContext, StringBuilder retVal, List<String> options)
     {

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=1296362&r1=1296361&r2=1296362&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 Mar  2 18:27:53 2012
@@ -139,7 +139,10 @@ public class HtmlFormatRenderer extends 
 
             if (escape)
             {
-                if (log.isLoggable(Level.FINE)) log.fine("renderOutputText writing '" + text + "'");
+                if (log.isLoggable(Level.FINE))
+                {
+                    log.fine("renderOutputText writing '" + text + "'");
+                }
                 writer.writeText(text, org.apache.myfaces.shared.renderkit.JSFAttr.VALUE_ATTR);
             }
             else
@@ -170,8 +173,9 @@ public class HtmlFormatRenderer extends 
             {
                 List<UIParameter> validParams = HtmlRendererUtils.getValidUIParameterChildren(
                         facesContext, htmlOutputFormat.getChildren(), false, false, false);
-                for (UIParameter param : validParams)
+                for (int i = 0, size = validParams.size(); i < size; i++)
                 {
+                    UIParameter param = validParams.get(i);
                     if (argsList == null)
                     {
                         argsList = new ArrayList<Object>();
@@ -197,7 +201,8 @@ public class HtmlFormatRenderer extends 
         }
         catch (Exception e)
         {
-            log.log(Level.SEVERE, "Error formatting message of component " + htmlOutputFormat.getClientId(facesContext));
+            log.log(Level.SEVERE, "Error formatting message of component "
+                                  + htmlOutputFormat.getClientId(facesContext));
             return "";
         }
     }

Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java?rev=1296362&r1=1296361&r2=1296362&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java Fri Mar  2 18:27:53 2012
@@ -143,7 +143,8 @@ public class FaceletViewDeclarationLangu
 
     private static final Class<?>[] ACTION_LISTENER_SIGNATURE = new Class[]{ActionEvent.class};
 
-    private static final Class<?>[] VALIDATOR_SIGNATURE = new Class[]{FacesContext.class, UIComponent.class, Object.class};
+    private static final Class<?>[] VALIDATOR_SIGNATURE
+            = new Class[]{FacesContext.class, UIComponent.class, Object.class};
 
     public static final String CHARACTER_ENCODING_KEY = "javax.faces.request.charset";
 
@@ -158,7 +159,8 @@ public class FaceletViewDeclarationLangu
      * Define the default buffer size value passed to ExternalContext.setResponseBufferResponse() and in a
      * servlet environment to HttpServletResponse.setBufferSize().
      */
-    @JSFWebConfigParam(since = "2.0", alias = "facelets.BUFFER_SIZE", classType = "java.lang.Integer", tags = "performance",
+    @JSFWebConfigParam(since = "2.0", alias = "facelets.BUFFER_SIZE", classType = "java.lang.Integer",
+            tags = "performance",
             desc = "Define the default buffer size value passed to ExternalContext.setResponseBufferResponse() and in "
                    + "a servlet environment to HttpServletResponse.setBufferSize()")
     public final static String PARAM_BUFFER_SIZE = "javax.faces.FACELETS_BUFFER_SIZE";
@@ -199,14 +201,16 @@ public class FaceletViewDeclarationLangu
     /**
      * Set of .taglib.xml files, separated by ';' that should be loaded by facelet engine.
      */
-    @JSFWebConfigParam(since = "2.0", desc = "Set of .taglib.xml files, separated by ';' that should be loaded by facelet engine.",
+    @JSFWebConfigParam(since = "2.0",
+            desc = "Set of .taglib.xml files, separated by ';' that should be loaded by facelet engine.",
             alias = "facelets.LIBRARIES")
     public final static String PARAM_LIBRARIES = "javax.faces.FACELETS_LIBRARIES";
 
     /**
      * Set of .taglib.xml files, separated by ';' that should be loaded by facelet engine.
      */
-    @JSFWebConfigParam(since = "2.0", desc = "Set of .taglib.xml files, separated by ';' that should be loaded by facelet engine.",
+    @JSFWebConfigParam(since = "2.0",
+            desc = "Set of .taglib.xml files, separated by ';' that should be loaded by facelet engine.",
             deprecated = true)
     private final static String PARAM_LIBRARIES_DEPRECATED = "facelets.LIBRARIES";
 
@@ -217,7 +221,8 @@ public class FaceletViewDeclarationLangu
      *
      * <p>By default is infinite (no active).</p>
      */
-    @JSFWebConfigParam(since = "2.0", defaultValue = "-1", alias = "facelets.REFRESH_PERIOD", classType = "java.lang.Long", tags = "performance")
+    @JSFWebConfigParam(since = "2.0", defaultValue = "-1", alias = "facelets.REFRESH_PERIOD",
+            classType = "java.lang.Long", tags = "performance")
     public final static String PARAM_REFRESH_PERIOD = "javax.faces.FACELETS_REFRESH_PERIOD";
 
     /**
@@ -242,7 +247,8 @@ public class FaceletViewDeclarationLangu
     @JSFWebConfigParam(since = "2.0", deprecated = true)
     private final static String PARAM_RESOURCE_RESOLVER_DEPRECATED = "facelets.RESOURCE_RESOLVER";
 
-    private final static String[] PARAMS_RESOURCE_RESOLVER = {PARAM_RESOURCE_RESOLVER, PARAM_RESOURCE_RESOLVER_DEPRECATED};
+    private final static String[] PARAMS_RESOURCE_RESOLVER
+            = {PARAM_RESOURCE_RESOLVER, PARAM_RESOURCE_RESOLVER_DEPRECATED};
 
     /**
      * Skip comments found on a facelet file.
@@ -734,9 +740,12 @@ public class FaceletViewDeclarationLangu
             // In the spec javadoc this variable is referred as forAttributeValue, but
             // note it is also called curTargetName
             String forValue = currentHandler.getFor();
-
-            for (AttachedObjectTarget currentTarget : targetList)
+            
+            // perf: targetList is always arrayList: see AttachedObjectTargetHandler.apply 
+            // and ClientBehaviorHandler.apply 
+            for (int k = 0, targetsSize = targetList.size(); k < targetsSize; k++)
             {
+                AttachedObjectTarget currentTarget = targetList.get(k);
                 FaceletCompositionContext mctx = FaceletCompositionContext.getCurrentInstance();
 
                 if ((forValue != null && forValue.equals(currentTarget.getName())) &&
@@ -747,8 +756,11 @@ public class FaceletViewDeclarationLangu
                                 (currentTarget instanceof ValueHolderAttachedObjectTarget &&
                                         currentHandler instanceof ValueHolderAttachedObjectHandler)))
                 {
-                    for (UIComponent component : currentTarget.getTargets(topLevelComponent))
+                    // perf: getTargets return ArrayList - see getTargets implementations
+                    List<UIComponent> targets = currentTarget.getTargets(topLevelComponent);
+                    for (int l = 0, targetsCount = targets.size(); l < targetsCount; l++)
                     {
+                        UIComponent component = targets.get(l);
                         // If we found composite components when traverse the tree
                         // we have to call this one recursively, because each composite component
                         // should have its own AttachedObjectHandler list, filled earlier when
@@ -790,8 +802,10 @@ public class FaceletViewDeclarationLangu
                     if ((eventName != null && eventName.equals(currentTarget.getName())) ||
                             (eventName == null && isDefaultEvent))
                     {
-                        for (UIComponent component : currentTarget.getTargets(topLevelComponent))
+                        List<UIComponent> targets = currentTarget.getTargets(topLevelComponent);
+                        for (int j = 0, targetssize = targets.size(); j < targetssize; j++)
                         {
+                            UIComponent component = targets.get(j);
                             // If we found composite components when traverse the tree
                             // we have to call this one recursively, because each composite component
                             // should have its own AttachedObjectHandler list, filled earlier when
@@ -818,10 +832,13 @@ public class FaceletViewDeclarationLangu
                             }
                             else
                             {
-                                if (currentHandler instanceof ClientBehaviorRedirectBehaviorAttachedObjectHandlerWrapper)
+                                if (currentHandler instanceof
+                                        ClientBehaviorRedirectBehaviorAttachedObjectHandlerWrapper)
                                 {
-                                    currentHandler.applyAttachedObject(context, new ClientBehaviorRedirectEventComponentWrapper(component, 
-                                            ((ClientBehaviorRedirectBehaviorAttachedObjectHandlerWrapper) currentHandler).getWrappedEventName(), eventName));
+                                    currentHandler.applyAttachedObject(context,
+                                            new ClientBehaviorRedirectEventComponentWrapper(component,
+                                            ((ClientBehaviorRedirectBehaviorAttachedObjectHandlerWrapper)
+                                                    currentHandler).getWrappedEventName(), eventName));
                                 }
                                 else
                                 {
@@ -836,10 +853,10 @@ public class FaceletViewDeclarationLangu
     }
 
     @Override
-    public void retargetMethodExpressions(FacesContext context,
-            UIComponent topLevelComponent)
+    public void retargetMethodExpressions(FacesContext context, UIComponent topLevelComponent)
     {
-        BeanInfo compositeComponentMetadata = (BeanInfo) topLevelComponent.getAttributes().get(UIComponent.BEANINFO_KEY);
+        BeanInfo compositeComponentMetadata
+                = (BeanInfo) topLevelComponent.getAttributes().get(UIComponent.BEANINFO_KEY);
 
         if (compositeComponentMetadata == null)
         {
@@ -1318,7 +1335,8 @@ public class FaceletViewDeclarationLangu
     }
 
     @SuppressWarnings("unchecked")
-    private MethodExpression reWrapMethodExpression(MethodExpression createdMethodExpression, ValueExpression originalValueExpression)
+    private MethodExpression reWrapMethodExpression(MethodExpression createdMethodExpression,
+                                                    ValueExpression originalValueExpression)
     {
         if (originalValueExpression instanceof LocationValueExpression)
         {
@@ -1767,16 +1785,19 @@ public class FaceletViewDeclarationLangu
         long refreshPeriod;
         if (context.isProjectStage(ProjectStage.Production))
         {
-            refreshPeriod = WebConfigParamUtils.getLongInitParameter(eContext, PARAMS_REFRESH_PERIOD, DEFAULT_REFRESH_PERIOD_PRODUCTION);
+            refreshPeriod = WebConfigParamUtils.getLongInitParameter(eContext, PARAMS_REFRESH_PERIOD,
+                    DEFAULT_REFRESH_PERIOD_PRODUCTION);
         }
         else
         {
-            refreshPeriod = WebConfigParamUtils.getLongInitParameter(eContext, PARAMS_REFRESH_PERIOD, DEFAULT_REFRESH_PERIOD);
+            refreshPeriod = WebConfigParamUtils.getLongInitParameter(eContext, PARAMS_REFRESH_PERIOD,
+                    DEFAULT_REFRESH_PERIOD);
         }
 
         // resource resolver
         ResourceResolver resolver = new DefaultResourceResolver();
-        String faceletsResourceResolverClassName = WebConfigParamUtils.getStringInitParameter(eContext, PARAMS_RESOURCE_RESOLVER, null);
+        String faceletsResourceResolverClassName = WebConfigParamUtils.getStringInitParameter(eContext,
+                PARAMS_RESOURCE_RESOLVER, null);
         if (faceletsResourceResolverClassName != null)
         {
             ArrayList<String> classNames = new ArrayList<String>(1);
@@ -2123,7 +2144,8 @@ public class FaceletViewDeclarationLangu
         ExternalContext eContext = context.getExternalContext();
 
         // skip comments?
-        compiler.setTrimmingComments(WebConfigParamUtils.getBooleanInitParameter(eContext, PARAMS_SKIP_COMMENTS, false));
+        compiler.setTrimmingComments(WebConfigParamUtils.getBooleanInitParameter(
+                eContext, PARAMS_SKIP_COMMENTS, false));
     }
 
     /**

Modified: myfaces/core/branches/2.0.x/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java?rev=1296362&r1=1296361&r2=1296362&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java (original)
+++ myfaces/core/branches/2.0.x/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java Fri Mar  2 18:27:53 2012
@@ -2164,10 +2164,12 @@ public final class HtmlRendererUtils
         {
             finalParams.add('\'' + escapeJavaScriptForChain(serverEventCode) + '\'');
         }
-        Iterator<String> it = finalParams.iterator();
+        
         // It's possible that there are no behaviors to render.  For example, if we have
         // <f:ajax disabled="true" /> as the only behavior.
-        if (it.hasNext())
+        
+        int size = finalParams.size();
+        if (size > 0)
         {
             if (!submitting)
             {
@@ -2177,10 +2179,12 @@ public final class HtmlRendererUtils
             //behavior and scripts
             retVal.append("jsf.util.chain(document.getElementById('"
                     + targetClientId + "'), event,");
-            while (it.hasNext())
+            int cursor = 0;
+            while (cursor != size)
             {
-                retVal.append(it.next());
-                if (it.hasNext())
+                retVal.append(finalParams.get(cursor));
+                cursor++;
+                if (cursor != size)
                 {
                     retVal.append(", ");
                 }

Modified: myfaces/core/branches/2.0.x/shared/src/main/java/org/apache/myfaces/shared/util/ArrayUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/shared/src/main/java/org/apache/myfaces/shared/util/ArrayUtils.java?rev=1296362&r1=1296361&r2=1296362&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/shared/src/main/java/org/apache/myfaces/shared/util/ArrayUtils.java (original)
+++ myfaces/core/branches/2.0.x/shared/src/main/java/org/apache/myfaces/shared/util/ArrayUtils.java Fri Mar  2 18:27:53 2012
@@ -19,6 +19,9 @@
 package org.apache.myfaces.shared.util;
 
 import java.lang.reflect.Array;
+import java.util.Collection;
+import java.util.List;
+import java.util.RandomAccess;
 
 /**
  * Utility class for managing arrays
@@ -228,7 +231,29 @@ public class ArrayUtils
         return false;
     }
 
-
+    /**
+     * Same as {@link Collection#addAll(Collection)} but in case of RandomAccess iterates over indices 
+     */
+    public static <T> void addAll(Collection<? super T> collection, Collection<? extends T> toAdd)
+    {
+        if (collection == null || toAdd == null)
+        {
+            return;
+        }
+        if (toAdd instanceof RandomAccess)
+        {
+            List<? extends T> randomAccess = (List<? extends T>) toAdd;
+            for (int i = 0, size = randomAccess.size(); i < size; i++)
+            {
+                T element = randomAccess.get(i);
+                collection.add(element);
+            }
+        }
+        else
+        {
+            collection.addAll(toAdd);
+        }
+    }
 
 //    public static void main(String[] args)
 //    {