You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ha...@apache.org on 2023/12/20 23:28:33 UTC

(royale-asjs) branch develop updated: Moved the getDepth method to HierachicalData to allow for optimization in subclasses

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 fbfc2bbe40 Moved the getDepth method to HierachicalData to allow for optimization in subclasses
fbfc2bbe40 is described below

commit fbfc2bbe40ba1d138c765176994a7290489c7068
Author: Harbs <ha...@in-tools.com>
AuthorDate: Thu Dec 21 01:28:26 2023 +0200

    Moved the getDepth method to HierachicalData to allow for optimization in subclasses
---
 .../org/apache/royale/collections/FlattenedList.as | 43 ++++++----------------
 .../apache/royale/collections/HierarchicalData.as  | 21 ++++++++++-
 .../apache/royale/collections/IHierarchicalData.as | 10 +++++
 .../org/apache/royale/collections/TreeData.as      |  4 +-
 4 files changed, 43 insertions(+), 35 deletions(-)

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 1409971af4..f0449c2a35 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
@@ -186,36 +186,19 @@ package org.apache.royale.collections
 		
 		/**
 		 * Returns the depth of the node with the root being zero.
-         *  
-         *  @langversion 3.0
-         *  @playerversion Flash 10.2
-         *  @playerversion AIR 2.6
-         *  @productversion Royale 0.0
+		 * 
+		 * Returning the depth from the HierachicalData allows for optimization in client code.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.0
 		 */
 		public function getDepth(node:Object):int
 		{
-			var depth:int = godeep(node, hdata.getRoot(), 0);
-			return depth;
-		}
-		
-		/**
-		 * @private
-		 */
-		private function godeep(seeking:Object, node:Object, depth:int):int
-		{
-			if (seeking == node) return depth;
-			
-			var children:Array = hdata.getChildren(node) as Array;
-			if (children) {
-				var len:int = children.length;
-				for (var i:int=0; i < len; i++) {
-					var newDepth:int = godeep(seeking, children[i], depth+1)
-					if (newDepth > 0) return newDepth;
-				}
-			}
-			
-			return -1;
+			return hdata.getDepth(node);
 		}
+
 		/**
 		 * When adding items from outside FlattenedList, it needs to be added to the data structure as well.
 		 * @royaleignorecoercion Array
@@ -242,17 +225,13 @@ package org.apache.royale.collections
 			var topLevel:Array = hdata.getChildren(hdata.getRoot()) as Array;
 			var upperIdx:int = topLevel.length - 1;
 			if (index > 0 && index < upperIdx)
-			{
 				topLevel.splice(index, 1);
-			}
+
 			else if (index == upperIdx)
-			{
 				topLevel.pop();
-			}
+
 			else if (index == 0)
-			{
 				topLevel.shift();
-			}
 			
 			return super.removeItemAt(index);
 		}
diff --git a/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/HierarchicalData.as b/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/HierarchicalData.as
index dce94df2b1..b90a1aa2c3 100644
--- a/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/HierarchicalData.as
+++ b/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/HierarchicalData.as
@@ -271,7 +271,26 @@ package org.apache.royale.collections
 		
 		public function getDepth(node:Object):int
 		{
-			return _flatList.getDepth(node);
+			var depth:int = godeep(node, source, 0);
+			return depth;
+		}
+		/**
+		 * @private
+		 */
+		private function godeep(seeking:Object, node:Object, depth:int):int
+		{
+			if (seeking == node) return depth;
+			
+			var children:Array = getChildren(node) as Array;
+			if (children) {
+				var len:int = children.length;
+				for (var i:int=0; i < len; i++) {
+					var newDepth:int = godeep(seeking, children[i], depth+1)
+					if (newDepth > 0) return newDepth;
+				}
+			}
+			
+			return -1;
 		}
 
 	}
diff --git a/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/IHierarchicalData.as b/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/IHierarchicalData.as
index c13e8a3f0c..ef8362d610 100644
--- a/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/IHierarchicalData.as
+++ b/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/IHierarchicalData.as
@@ -114,6 +114,16 @@ public interface IHierarchicalData extends IEventDispatcher
      *  @productversion Royale 0.0
      */
     function getRoot():Object;
+
+    /**
+     * Returns the depth of the node with the root being zero.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.0
+     */
+    function getDepth(node:Object):int;
 }
 
 }
diff --git a/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/TreeData.as b/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/TreeData.as
index 7c2386d8eb..f4d60799ff 100644
--- a/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/TreeData.as
+++ b/frameworks/projects/Collections/src/main/royale/org/apache/royale/collections/TreeData.as
@@ -59,7 +59,7 @@ package org.apache.royale.collections
 		
 		public function hasChildren(node:Object):Boolean
 		{
-			return _flatList.hasChildren(node);
+			return _hierarchicalData.hasChildren(node);
 		}
 		
 		public function isOpen(node:Object):Boolean
@@ -79,7 +79,7 @@ package org.apache.royale.collections
 		
 		public function getDepth(node:Object):int
 		{
-			return _flatList.getDepth(node);
+			return _hierarchicalData.getDepth(node);
 		}
 		
 		// ICollectionData