From b83240f9026489a241430e5d33ffbebdf93d14a5 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Thu, 22 Aug 2013 11:28:39 +0300 Subject: [PATCH] Optimize CssLayout hierarchy update (#11284) This change also adds some profiling for CssLayoutConnector. Change-Id: Ia567c2c0ed2cff2c73a9019cea0f9a0240955dc7 --- client/src/com/vaadin/client/ui/VCssLayout.java | 3 +++ .../client/ui/csslayout/CssLayoutConnector.java | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/client/src/com/vaadin/client/ui/VCssLayout.java b/client/src/com/vaadin/client/ui/VCssLayout.java index 4357116707..c073c18ccb 100644 --- a/client/src/com/vaadin/client/ui/VCssLayout.java +++ b/client/src/com/vaadin/client/ui/VCssLayout.java @@ -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) { diff --git a/client/src/com/vaadin/client/ui/csslayout/CssLayoutConnector.java b/client/src/com/vaadin/client/ui/csslayout/CssLayoutConnector.java index 4c8d1a3ecc..b6dfffcc55 100644 --- a/client/src/com/vaadin/client/ui/csslayout/CssLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/csslayout/CssLayoutConnector.java @@ -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"); } /** -- 2.39.5