]> source.dussan.org Git - vaadin-framework.git/commitdiff
Optimize CssLayout hierarchy update (#11284)
authorHenri Sara <hesara@vaadin.com>
Thu, 22 Aug 2013 08:28:39 +0000 (11:28 +0300)
committerVaadin Code Review <review@vaadin.com>
Tue, 27 Aug 2013 09:20:21 +0000 (09:20 +0000)
This change also adds some profiling for CssLayoutConnector.

Change-Id: Ia567c2c0ed2cff2c73a9019cea0f9a0240955dc7

client/src/com/vaadin/client/ui/VCssLayout.java
client/src/com/vaadin/client/ui/csslayout/CssLayoutConnector.java

index 4357116707df83400d24e2d4e196ae1cffdec16b..c073c18ccb0be81a15aaf3895b8b436a31024803 100644 (file)
@@ -40,7 +40,10 @@ public class VCssLayout extends FlowPanel {
 
     /**
      * For internal use only. May be removed or replaced in the future.
+     * 
+     * @deprecated since 7.1.4 no longer used by the framework, might be removed
      */
+    @Deprecated
     public void addOrMove(Widget child, int index) {
         Profiler.enter("VCssLayout.addOrMove");
         if (child.getParent() == this) {
index 4c8d1a3eccbc6a8176e1ad2c0a0777e1eeba3564..b6dfffcc55c8373e2e2af004356aa509ae23562f 100644 (file)
@@ -22,6 +22,7 @@ import com.vaadin.client.BrowserInfo;
 import com.vaadin.client.ComponentConnector;
 import com.vaadin.client.ConnectorHierarchyChangeEvent;
 import com.vaadin.client.FastStringMap;
+import com.vaadin.client.Profiler;
 import com.vaadin.client.Util;
 import com.vaadin.client.VCaption;
 import com.vaadin.client.communication.StateChangeEvent;
@@ -120,17 +121,23 @@ public class CssLayoutConnector extends AbstractLayoutConnector {
      */
     @Override
     public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) {
-        int index = 0;
+        Profiler.enter("CssLayoutConnector.onConnectorHierarchyChange");
+        Profiler.enter("CssLayoutConnector.onConnectorHierarchyChange add children");
+        // for large layouts, significantly faster to clear the list and always
+        // append to the end than to move the children around
+        getWidget().clear();
         for (ComponentConnector child : getChildComponents()) {
             VCaption childCaption = childIdToCaption
                     .get(child.getConnectorId());
             if (childCaption != null) {
-                getWidget().addOrMove(childCaption, index++);
+                getWidget().add(childCaption);
             }
-            getWidget().addOrMove(child.getWidget(), index++);
+            getWidget().add(child.getWidget());
         }
+        Profiler.leave("CssLayoutConnector.onConnectorHierarchyChange add children");
 
         // Detach old child widgets and possibly their caption
+        Profiler.enter("CssLayoutConnector.onConnectorHierarchyChange remove old children");
         for (ComponentConnector child : event.getOldChildren()) {
             if (child.getParent() == this) {
                 // Skip current children
@@ -143,6 +150,8 @@ public class CssLayoutConnector extends AbstractLayoutConnector {
                 getWidget().remove(vCaption);
             }
         }
+        Profiler.leave("CssLayoutConnector.onConnectorHierarchyChange remove old children");
+        Profiler.leave("CssLayoutConnector.onConnectorHierarchyChange");
     }
 
     /**