From 6dc46c5cfc66defaa7ed2350f20bf2224b419d82 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Wed, 28 Aug 2013 12:34:53 +0300 Subject: Use the add() path of CssLayout only when appending to the end (#11284) 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 | 15 ++++++++++++--- .../vaadin/client/ui/csslayout/CssLayoutConnector.java | 8 +++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/client/src/com/vaadin/client/ui/VCssLayout.java b/client/src/com/vaadin/client/ui/VCssLayout.java index c073c18ccb..e4fac6acb3 100644 --- a/client/src/com/vaadin/client/ui/VCssLayout.java +++ b/client/src/com/vaadin/client/ui/VCssLayout.java @@ -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"); } } diff --git a/client/src/com/vaadin/client/ui/csslayout/CssLayoutConnector.java b/client/src/com/vaadin/client/ui/csslayout/CssLayoutConnector.java index b6dfffcc55..45e52c890e 100644 --- a/client/src/com/vaadin/client/ui/csslayout/CssLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/csslayout/CssLayoutConnector.java @@ -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"); -- cgit v1.2.3