myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1539923 - in /myfaces/core/trunk: api/src/main/java/javax/faces/component/ impl/src/main/java/org/apache/myfaces/view/facelets/
Date Fri, 08 Nov 2013 05:15:25 GMT
Author: lu4242
Date: Fri Nov  8 05:15:24 2013
New Revision: 1539923

URL: http://svn.apache.org/r1539923
Log:
MYFACES-3823 [perf] use a preinitialized table of unique ids for UIViewRoot.createUniqueId(...)

Modified:
    myfaces/core/trunk/api/src/main/java/javax/faces/component/UIForm.java
    myfaces/core/trunk/api/src/main/java/javax/faces/component/UINamingContainer.java
    myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewRoot.java
    myfaces/core/trunk/api/src/main/java/javax/faces/component/_ComponentUtils.java
    myfaces/core/trunk/api/src/main/java/javax/faces/component/_ViewAttributeMap.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UIForm.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UIForm.java?rev=1539923&r1=1539922&r2=1539923&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UIForm.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UIForm.java Fri Nov  8 05:15:24
2013
@@ -93,9 +93,9 @@ public class UIForm extends UIComponentB
         // UNIQUE_ID_PREFIX, and will be unique within this UIViewRoot.
         if(seed==null)
         {
-            Long uniqueIdCounter = (Long) getStateHelper().get(PropertyKeys.uniqueIdCounter);
+            Integer uniqueIdCounter = (Integer) getStateHelper().get(PropertyKeys.uniqueIdCounter);
             uniqueIdCounter = (uniqueIdCounter == null) ? 0 : uniqueIdCounter;
-            getStateHelper().put(PropertyKeys.uniqueIdCounter, (uniqueIdCounter+1L));
+            getStateHelper().put(PropertyKeys.uniqueIdCounter, (uniqueIdCounter+1));
             return bld.append(UIViewRoot.UNIQUE_ID_PREFIX).append(uniqueIdCounter).toString();
   
         }
         // Optionally, a unique seed value can be supplied by component creators
@@ -479,5 +479,4 @@ public class UIForm extends UIComponentB
     {
         getStateHelper().put(PropertyKeys.prependId, prependId ); 
     }
-
 }

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UINamingContainer.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UINamingContainer.java?rev=1539923&r1=1539922&r2=1539923&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UINamingContainer.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UINamingContainer.java Fri
Nov  8 05:15:24 2013
@@ -77,9 +77,9 @@ public class UINamingContainer extends U
         // and will be unique within this UIViewRoot.
         if(seed==null)
         {
-            Long uniqueIdCounter = (Long) getStateHelper().get(PropertyKeys.uniqueIdCounter);
+            Integer uniqueIdCounter = (Integer) getStateHelper().get(PropertyKeys.uniqueIdCounter);
             uniqueIdCounter = (uniqueIdCounter == null) ? 0 : uniqueIdCounter;
-            getStateHelper().put(PropertyKeys.uniqueIdCounter, (uniqueIdCounter+1L));
+            getStateHelper().put(PropertyKeys.uniqueIdCounter, (uniqueIdCounter+1));
             return bld.append(UIViewRoot.UNIQUE_ID_PREFIX).append(uniqueIdCounter).toString();
   
         }
         // Optionally, a unique seed value can be supplied by component creators

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewRoot.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewRoot.java?rev=1539923&r1=1539922&r2=1539923&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewRoot.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UIViewRoot.java Fri Nov  8
05:15:24 2013
@@ -413,7 +413,6 @@ public class UIViewRoot extends UICompon
      */
     public String createUniqueId(FacesContext context, String seed)
     {
-        StringBuilder bld = _getSharedStringBuilder(context);
 
         // Generate an identifier for a component. The identifier will be prefixed with
         // UNIQUE_ID_PREFIX, and will be unique within this UIViewRoot.
@@ -421,23 +420,43 @@ public class UIViewRoot extends UICompon
         {
             if (isResourceDependencyUniqueId())
             {
-                Long uniqueIdCounter = (Long) getStateHelper().get(PropertyKeys.resourceDependencyUniqueIdCounter);
+                Integer uniqueIdCounter = (Integer) getStateHelper().get(
+                    PropertyKeys.resourceDependencyUniqueIdCounter);
                 uniqueIdCounter = (uniqueIdCounter == null) ? 0 : uniqueIdCounter;
-                getStateHelper().put(PropertyKeys.resourceDependencyUniqueIdCounter, (uniqueIdCounter+1L));
-                return bld.append(UNIQUE_ID_PREFIX).append("__rd_").append(uniqueIdCounter).toString();
+                getStateHelper().put(PropertyKeys.resourceDependencyUniqueIdCounter, (uniqueIdCounter+1));
+                if (uniqueIdCounter >= _ComponentUtils.UNIQUE_COMPONENT_RD_IDS_SIZE)
+                {
+                    StringBuilder bld = _getSharedStringBuilder(context);
+                    return bld.append(UNIQUE_ID_PREFIX).append(
+                        _ComponentUtils.RD_ID_PREFIX).append(uniqueIdCounter).toString();
+                }
+                else
+                {
+                    return _ComponentUtils.UNIQUE_COMPONENT_RD_IDS[uniqueIdCounter];
+                }
             }
             else
             {
-                Long uniqueIdCounter = (Long) getStateHelper().get(PropertyKeys.uniqueIdCounter);
+                Integer uniqueIdCounter = (Integer) getStateHelper().get(PropertyKeys.uniqueIdCounter);
                 uniqueIdCounter = (uniqueIdCounter == null) ? 0 : uniqueIdCounter;
-                getStateHelper().put(PropertyKeys.uniqueIdCounter, (uniqueIdCounter+1L));
-                return bld.append(UNIQUE_ID_PREFIX).append("__v_").append(uniqueIdCounter).toString();
+                getStateHelper().put(PropertyKeys.uniqueIdCounter, (uniqueIdCounter+1));
+                if (uniqueIdCounter >= _ComponentUtils.UNIQUE_COMPONENT_V_IDS_SIZE)
+                {
+                    StringBuilder bld = _getSharedStringBuilder(context);
+                    return bld.append(UNIQUE_ID_PREFIX).append(
+                        _ComponentUtils.V_ID_PREFIX).append(uniqueIdCounter).toString();
+                }
+                else
+                {
+                    return _ComponentUtils.UNIQUE_COMPONENT_V_IDS[uniqueIdCounter];
+                }
             }
         }
         // Optionally, a unique seed value can be supplied by component creators which
         // should be included in the generated unique id.
         else
         {
+            StringBuilder bld = _getSharedStringBuilder(context);
             return bld.append(UNIQUE_ID_PREFIX).append(seed).toString();
         }
     }

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/_ComponentUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/_ComponentUtils.java?rev=1539923&r1=1539922&r2=1539923&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/_ComponentUtils.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/_ComponentUtils.java Fri Nov
 8 05:15:24 2013
@@ -33,6 +33,32 @@ import java.util.Collection;
  */
 class _ComponentUtils
 {
+    public static final String V_ID_PREFIX = "__v_";
+    public static final String RD_ID_PREFIX = "__rd_";
+    public static final int UNIQUE_COMPONENT_V_IDS_SIZE = 50;
+    public static final int UNIQUE_COMPONENT_RD_IDS_SIZE = 50;
+    public static final String[] UNIQUE_COMPONENT_V_IDS;
+    public static final String[] UNIQUE_COMPONENT_RD_IDS;
+    
+    static 
+    {
+        String[] uniqueV = new String[UNIQUE_COMPONENT_V_IDS_SIZE];
+        String[] uniqueRD = new String[UNIQUE_COMPONENT_RD_IDS_SIZE];
+        StringBuilder bld = new StringBuilder(20);
+        for (int i = 0; i < UNIQUE_COMPONENT_V_IDS_SIZE; i++)
+        {
+            uniqueV[i] = bld.append(UIViewRoot.UNIQUE_ID_PREFIX).append("__v_").append(i).toString();
+            bld.setLength(0);
+        }
+        for (int i = 0; i < UNIQUE_COMPONENT_RD_IDS_SIZE; i++)
+        {
+            uniqueRD[i] = bld.append(UIViewRoot.UNIQUE_ID_PREFIX).append("__rd_").append(i).toString();
+            bld.setLength(0);
+        }
+        UNIQUE_COMPONENT_RD_IDS = uniqueRD;
+        UNIQUE_COMPONENT_V_IDS = uniqueV;
+    }
+    
     private _ComponentUtils()
     {
     }

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/_ViewAttributeMap.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/_ViewAttributeMap.java?rev=1539923&r1=1539922&r2=1539923&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/_ViewAttributeMap.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/_ViewAttributeMap.java Fri
Nov  8 05:15:24 2013
@@ -114,7 +114,7 @@ class _ViewAttributeMap implements Map<S
         if (UNIQUE_ID_COUNTER_KEY.length() == keyLength
             && UNIQUE_ID_COUNTER_KEY.equals(key))
         {
-            Long v = (Long) _root.getStateHelper().get(UIViewRoot.PropertyKeys.uniqueIdCounter);
+            Integer v = (Integer) _root.getStateHelper().get(UIViewRoot.PropertyKeys.uniqueIdCounter);
             _root.getStateHelper().put(UIViewRoot.PropertyKeys.uniqueIdCounter, value);
             return v;
         }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java?rev=1539923&r1=1539922&r2=1539923&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
Fri Nov  8 05:15:24 2013
@@ -355,7 +355,7 @@ public class DefaultFaceletsStateManagem
             {
                 states = (Map<String, Object>) state[1];
                 //Save the last unique id counter key in UIViewRoot
-                Long lastUniqueIdCounter = (Long) view.getAttributes().get(UNIQUE_ID_COUNTER_KEY);
+                Integer lastUniqueIdCounter = (Integer) view.getAttributes().get(UNIQUE_ID_COUNTER_KEY);
                 
                 // Visit the children and restore their state.
                 boolean emptyState = false;
@@ -401,9 +401,9 @@ public class DefaultFaceletsStateManagem
                 }
                 if (lastUniqueIdCounter != null)
                 {
-                    Long newUniqueIdCounter = (Long) view.getAttributes().get(UNIQUE_ID_COUNTER_KEY);
+                    Integer newUniqueIdCounter = (Integer) view.getAttributes().get(UNIQUE_ID_COUNTER_KEY);
                     if (newUniqueIdCounter != null && 
-                        lastUniqueIdCounter.longValue() > newUniqueIdCounter.longValue())
+                        lastUniqueIdCounter.intValue() > newUniqueIdCounter.intValue())
                     {
                         // The unique counter was restored by a side effect of 
                         // restoreState() over UIViewRoot with a lower count,
@@ -669,8 +669,8 @@ public class DefaultFaceletsStateManagem
             
             // As required by ResponseStateManager, the return value is an Object array.
 First
             // element is the structure object, second is the state map.
-            Long uniqueIdCount = (Long) view.getAttributes().get(UNIQUE_ID_COUNTER_KEY);
-            if (uniqueIdCount != null && !uniqueIdCount.equals(1L))
+            Integer uniqueIdCount = (Integer) view.getAttributes().get(UNIQUE_ID_COUNTER_KEY);
+            if (uniqueIdCount != null && !uniqueIdCount.equals(1))
             {
                 serializedView = new Object[] { null, states, uniqueIdCount };
             }



Mime
View raw message