This is an automated email from the ASF dual-hosted git repository.
harbs pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
The following commit(s) were added to refs/heads/develop by this push:
new 400ffc21b1 Optimizations for closing tree nodes
400ffc21b1 is described below
commit 400ffc21b1d80c94125e1524426e5d16655c6182
Author: Harbs <[email protected]>
AuthorDate: Wed Dec 20 19:19:35 2023 +0200
Optimizations for closing tree nodes
---
.../html/beads/TreeItemRendererInitializer.as | 82 ++++++++++++----------
.../org/apache/royale/collections/FlattenedList.as | 23 +++---
2 files changed, 61 insertions(+), 44 deletions(-)
diff --git
a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/TreeItemRendererInitializer.as
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/TreeItemRendererInitializer.as
index 3f31e6b780..5940193a5b 100644
---
a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/TreeItemRendererInitializer.as
+++
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/TreeItemRendererInitializer.as
@@ -17,25 +17,25 @@
//
////////////////////////////////////////////////////////////////////////////////
package org.apache.royale.html.beads
-{
-
- import org.apache.royale.collections.TreeData;
- import org.apache.royale.core.Bead;
- import org.apache.royale.core.IDataProviderModel;
- import org.apache.royale.core.IIndexedItemRenderer;
- import org.apache.royale.core.IIndexedItemRendererInitializer;
- import org.apache.royale.core.IItemRenderer;
- import org.apache.royale.core.IItemRendererOwnerView;
- import org.apache.royale.core.IListDataItemRenderer;
- import org.apache.royale.core.IStrand;
- import org.apache.royale.core.IUIBase;
- import org.apache.royale.core.SimpleCSSStyles;
- import org.apache.royale.core.UIBase;
- import org.apache.royale.html.supportClasses.TreeListData;
+{
+ import org.apache.royale.collections.TreeData;
+ import org.apache.royale.core.Bead;
+ import org.apache.royale.core.IDataProviderModel;
+ import org.apache.royale.core.IIndexedItemRenderer;
+ import org.apache.royale.core.IIndexedItemRendererInitializer;
+ import org.apache.royale.core.IItemRenderer;
+ import org.apache.royale.core.IItemRendererOwnerView;
+ import org.apache.royale.core.IListDataItemRenderer;
+ import org.apache.royale.core.IStrand;
+ import org.apache.royale.core.IUIBase;
+ import org.apache.royale.core.SimpleCSSStyles;
+ import org.apache.royale.core.UIBase;
+ import org.apache.royale.html.supportClasses.TreeListData;
+
/**
* The TreeItemRendererInitializer class initializes item renderers
- * in tree classes.
+ * in tree classes.
*
* @langversion 3.0
* @playerversion Flash 10.2
@@ -62,25 +62,35 @@ package org.apache.royale.html.beads
*/
override public function
initializeIndexedItemRenderer(ir:IIndexedItemRenderer, data:Object,
index:int):void
{
- if (!dataProviderModel)
- return;
-
- super.initializeIndexedItemRenderer(ir, data, index);
-
- var treeData:TreeData = dataProviderModel.dataProvider as TreeData;
- var depth:int = treeData.getDepth(data);
- var isOpen:Boolean = treeData.isOpen(data);
- var hasChildren:Boolean = treeData.hasChildren(data);
-
- // Set the listData with the depth of this item
- var treeListData:TreeListData = new TreeListData();
- treeListData.depth = depth;
- treeListData.isOpen = isOpen;
- treeListData.hasChildren = hasChildren;
-
- (ir as IListDataItemRenderer).listData = treeListData;
-
- }
-
+ if (!dataProviderModel)
+ return;
+ /**
+ * For the vast majority of cases,
+ * there is no need to reinitialize the whole item
renderer on an update.
+ * Just updating the index and nothing else can save a
lot of computation.
+ * This is especially true for calculating node depth
which can be expensive
+ * for large data sets where the calculation is not
optimized in subclasses.
+ */
+ if(ir.data == data)
+ {
+ ir.index = index;
+ return;
+ }
+
+ super.initializeIndexedItemRenderer(ir, data, index);
+
+ var treeData:TreeData = dataProviderModel.dataProvider
as TreeData;
+ var depth:int = treeData.getDepth(data);
+ var isOpen:Boolean = treeData.isOpen(data);
+ var hasChildren:Boolean = treeData.hasChildren(data);
+
+ // Set the listData with the depth of this item
+ var treeListData:TreeListData = new TreeListData();
+ treeListData.depth = depth;
+ treeListData.isOpen = isOpen;
+ treeListData.hasChildren = hasChildren;
+
+ (ir as IListDataItemRenderer).listData = treeListData;
+ }
}
}
diff --git
a/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/FlattenedList.as
b/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/FlattenedList.as
index c6aa12c8de..646ada7109 100644
---
a/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/FlattenedList.as
+++
b/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/FlattenedList.as
@@ -40,7 +40,7 @@ package org.apache.royale.collections
*/
public class FlattenedList extends ArrayList
{
- public var hdata:HierarchicalData;
+ public var hdata:IHierarchicalData;
public var openNodes:Array;
/**
@@ -51,7 +51,7 @@ package org.apache.royale.collections
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
- public function FlattenedList(hdata:HierarchicalData)
+ public function FlattenedList(hdata:IHierarchicalData)
{
super();
this.hdata = hdata;
@@ -162,10 +162,12 @@ package org.apache.royale.collections
openNodes.splice(i, 1);
var arr:Array = [];
addChildren(node, arr);
- i = getItemIndex(node) + 1;
- while (arr.length) {
- super.removeItemAt(i);
- arr.shift();
+ // removing them backwards should improve
performance in most cases
+ i = getItemIndex(node) + arr.length;
+ var len:int = arr.length;
+ for(var idx:int = 0; idx < len; idx++)
+ {
+ super.removeItemAt(i--);
}
}
updateNode(node);
@@ -214,10 +216,11 @@ package org.apache.royale.collections
}
/**
* When adding items from outside FlattenedList, it needs to be
added to the data structure as well.
+ * @royaleignorecoercion Array
*/
override public function addItemAt(item:Object, index:int):void{
super.addItemAt(item,index);
- var topLevel:Array = hdata.source.children;
+ var topLevel:Array = hdata.getChildren(hdata.getRoot())
as Array;
var len:int = topLevel.length;
if (index < len && index > 0)
topLevel.splice(index, 0, item);
@@ -229,8 +232,12 @@ package org.apache.royale.collections
topLevel.unshift(item);
}
+ /**
+ * When removing items from outside FlattenedList, it needs to
be added to the data structure as well.
+ * @royaleignorecoercion Array
+ */
override public function removeItemAt(index:int):Object{
- var topLevel:Array = hdata.source.children;
+ var topLevel:Array = hdata.getChildren(hdata.getRoot())
as Array;
var upperIdx:int = topLevel.length - 1;
if (index > 0 && index < upperIdx)
{