]> source.dussan.org Git - vaadin-framework.git/commitdiff
Improve performance of getMeasureTargetsJsArray (#16973).
authorFabian Lange <lange.fabian@gmail.com>
Mon, 2 Mar 2015 12:28:15 +0000 (13:28 +0100)
committerVaadin Code Review <review@vaadin.com>
Wed, 11 Mar 2015 08:20:14 +0000 (08:20 +0000)
This change optimizes the method
LayoutDependenyTree.getMeasureTargetsJsArray.

The previous code dumps both MeasureQueues and then iterates over the
vertical one and then checks if it is present in the horizontal one.
If it is not present it pushes the element to the array (which usually
invokes an arraycopy in js).

The new code adds both Queues to a new FastStringSet which does deal
with duplicates nicely.
While this is not much faster than the dumps, it avoids the array
allocations and the separate iteration for duplicate checking.

Change-Id: I2f643a2d0b32e4c2517efff16c196387f38f0d8a

client/src/com/vaadin/client/ui/layout/LayoutDependencyTree.java

index da3aed4bbcb829f60b400b976eb848782a81677c..af261c020820a43b70b5a0cb8056909d240f9eb0 100644 (file)
@@ -690,19 +690,10 @@ public class LayoutDependencyTree {
     }
 
     public JsArrayString getMeasureTargetsJsArray() {
-        FastStringSet horizontalQueue = getMeasureQueue(HORIZONTAL);
-        JsArrayString measureTargets = horizontalQueue.dump();
-
-        JsArrayString verticalDump = getMeasureQueue(VERTICAL).dump();
-        int length = verticalDump.length();
-        for (int i = 0; i < length; i++) {
-            String connectorId = verticalDump.get(i);
-            if (!horizontalQueue.contains(connectorId)) {
-                measureTargets.push(connectorId);
-            }
-        }
-
-        return measureTargets;
+        FastStringSet allMeasuredTargets = FastStringSet.create();
+        allMeasuredTargets.addAll(getMeasureQueue(HORIZONTAL));
+        allMeasuredTargets.addAll(getMeasureQueue(VERTICAL));
+        return allMeasuredTargets.dump();
     }
 
     public void logDependencyStatus(ComponentConnector connector) {