]> source.dussan.org Git - vaadin-framework.git/commitdiff
Use the add() path of CssLayout only when appending to the end (#11284)
authorHenri Sara <hesara@vaadin.com>
Wed, 28 Aug 2013 09:34:53 +0000 (12:34 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 28 Aug 2013 09:36:54 +0000 (09:36 +0000)
This should get the benefits of the previous optimization on initial
rendering without negatively affecting the performance when modifying a
layout with complex non-leaf children.

Change-Id: Id6fcf3e54469454c6a998a50037c8a93bfb46cf6

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

index c073c18ccb0be81a15aaf3895b8b436a31024803..e4fac6acb35da891aa555dfb25083b72a9e7651c 100644 (file)
@@ -40,20 +40,29 @@ 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) {
+            Profiler.enter("VCssLayout.addOrMove getWidgetIndex");
             int currentIndex = getWidgetIndex(child);
+            Profiler.leave("VCssLayout.addOrMove getWidgetIndex");
             if (index == currentIndex) {
                 Profiler.leave("VCssLayout.addOrMove");
                 return;
             }
+        } else if (index == getWidgetCount()) {
+            // optimized path for appending components - faster especially for
+            // initial rendering
+            Profiler.enter("VCssLayout.addOrMove add");
+            add(child);
+            Profiler.leave("VCssLayout.addOrMove add");
+            Profiler.leave("VCssLayout.addOrMove");
+            return;
         }
+        Profiler.enter("VCssLayout.addOrMove insert");
         insert(child, index);
+        Profiler.leave("VCssLayout.addOrMove insert");
         Profiler.leave("VCssLayout.addOrMove");
     }
 }
index b6dfffcc55c8373e2e2af004356aa509ae23562f..45e52c890e4b6b4d0f922cd400aa9b0d3bf7947c 100644 (file)
@@ -123,16 +123,14 @@ public class CssLayoutConnector extends AbstractLayoutConnector {
     public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) {
         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();
+        int index = 0;
         for (ComponentConnector child : getChildComponents()) {
             VCaption childCaption = childIdToCaption
                     .get(child.getConnectorId());
             if (childCaption != null) {
-                getWidget().add(childCaption);
+                getWidget().addOrMove(childCaption, index++);
             }
-            getWidget().add(child.getWidget());
+            getWidget().addOrMove(child.getWidget(), index++);
         }
         Profiler.leave("CssLayoutConnector.onConnectorHierarchyChange add children");