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 4979ff5b80 Reduce memory usage. Allow static (reusable) style beads.
4979ff5b80 is described below

commit 4979ff5b80bacb4023e86091be5db2072423519e
Author: Harbs <[email protected]>
AuthorDate: Sun Mar 22 10:35:40 2026 +0200

    Reduce memory usage. Allow static (reusable) style beads.
---
 .../royale/org/apache/royale/style/StyleUIBase.as  | 41 +++++++++++++---------
 .../royale/style/stylebeads/CompositeStyle.as      |  9 +----
 .../royale/style/stylebeads/ILeafStyleBead.as      |  1 +
 .../royale/style/stylebeads/LeafStyleBase.as       | 15 +++++---
 .../royale/style/stylebeads/StyleBeadBase.as       | 21 +++++++++--
 5 files changed, 54 insertions(+), 33 deletions(-)

diff --git 
a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/StyleUIBase.as
 
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/StyleUIBase.as
index 6fe7553d9c..4084447a8f 100644
--- 
a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/StyleUIBase.as
+++ 
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/StyleUIBase.as
@@ -123,32 +123,39 @@ package org.apache.royale.style
                                addStyleInternal(bead, false);
                        }
                }
+               /**
+                * @royaleignorecoercion 
org.apache.royale.style.stylebeads.ILeafStyleBead
+                */
                COMPILE::JS
                private function addStyleInternal(bead:IStyleBead, 
overrideExisting:Boolean):void
                {
-                       if(!styleTypes)
-                               styleTypes = new Map();
-                       
+                       if(bead.isLeaf)
+                               return addLeafStyleBead(bead as ILeafStyleBead, 
overrideExisting);
+
                        var leaves:Array = bead.getLeaves();
                        for each(var leaf:ILeafStyleBead in leaves)
                        {
                                assert(leaf.isLeaf, "getLeaves() should only 
return leaf style beads");
-                               /**
-                                * Only add the first found leaf for each style 
type.
-                                * This is to prevent duplicate styles from 
being added to the style sheet
-                                * and enables proper handling of styling 
overrides.
-                                */
-                               if(styleTypes.has(leaf.styleType))
-                               {
-                                       if(overrideExisting)
-                                               (styleTypes.get(leaf.styleType) 
as ILeafStyleBead).value = leaf.value;
+                               addLeafStyleBead(leaf, overrideExisting);
+                       }
+               }
+               COMPILE::JS
+               private function 
addLeafStyleBead(leaf:ILeafStyleBead,overrideExisting:Boolean):void
+               {
+                       if(!styleTypes)
+                               styleTypes = new Map();
+                       
+                       if(styleTypes.has(leaf.styleType))
+                       {
+                               if(overrideExisting)
+                                       (styleTypes.get(leaf.styleType) as 
ILeafStyleBead).value = leaf.value;
 
-                                       continue;
-                               }
-                               styleTypes.set(leaf.styleType, leaf);
-                               leaf.strand = this;
-                               _styleBeads.push(leaf);
+                               return;
                        }
+                       
+                       styleTypes.set(leaf.styleType, leaf);
+                       leaf.strand = this;
+                       _styleBeads.push(leaf);
                }
                COMPILE::JS
                private var styleTypes:Map;
diff --git 
a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/CompositeStyle.as
 
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/CompositeStyle.as
index 73d97670d3..ee11d841fc 100644
--- 
a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/CompositeStyle.as
+++ 
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/CompositeStyle.as
@@ -44,14 +44,7 @@ package org.apache.royale.style.stylebeads
                {
                        assert(styles && styles.length > 0, "Non-leaf style 
beads must have child styles");
                        // nothing to preprocess.
-                       var retVal:Array = [];
-                       for each(var style:IStyleBead in styles)
-                       {
-                               // Composite styles have no effect, so it 
should not insert itself into the hierarchy.
-                               style.parentStyle = parentStyle;
-                               retVal = retVal.concat(style.getLeaves());
-                       }
-               return retVal;
+                       return gatherLeaves(parentStyle);
                }
 
                //TODO: Figure this out.
diff --git 
a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/ILeafStyleBead.as
 
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/ILeafStyleBead.as
index 54c85a4188..581846f53c 100644
--- 
a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/ILeafStyleBead.as
+++ 
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/ILeafStyleBead.as
@@ -34,6 +34,7 @@ package org.apache.royale.style.stylebeads
                function set rulePrefix(value:String):void;
                function get ruleSuffix():String;
                function set ruleSuffix(value:String):void;
+               function isDecorated():Boolean;
 
 
        }
diff --git 
a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/LeafStyleBase.as
 
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/LeafStyleBase.as
index b5ac99f5a2..025bf9d562 100644
--- 
a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/LeafStyleBase.as
+++ 
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/LeafStyleBase.as
@@ -44,7 +44,7 @@ package org.apache.royale.style.stylebeads
                override public function getLeaves():Array
                {
                        // Walk up the chain decorating the styles.
-                       if(parentStyle)
+                       if(parentStyle && !isDecorated())
                                parentStyle.decorateChildStyle(this,[]);
                        return [this];
                }
@@ -170,10 +170,11 @@ package org.apache.royale.style.stylebeads
                        if(!calculatedSelector)
                                return "";
                        
-                       var str:String = selectorPrefix + selectorBase;
-                       if(str)
-                               str += "-";
-                       var selector:String = str + calculatedSelector;
+                       var selector:String;
+                       if(selectorPrefix || selectorBase)
+                               selector = selectorPrefix + selectorBase + "-" 
+ calculatedSelector;
+                       else
+                               selector = calculatedSelector;
                        /**
                         * Always add the rule automatically when accessing the 
selector if needed.
                         */
@@ -285,5 +286,9 @@ package org.apache.royale.style.stylebeads
                {
                        assert(false, "Leaf styles should not have child 
styles.");
                }
+               public function isDecorated():Boolean
+               {
+                       return _selectorPrefix != "";
+               }
        }
 }
\ No newline at end of file
diff --git 
a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/StyleBeadBase.as
 
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/StyleBeadBase.as
index e961436ecb..6b63942b4d 100644
--- 
a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/StyleBeadBase.as
+++ 
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/StyleBeadBase.as
@@ -55,13 +55,28 @@ package org.apache.royale.style.stylebeads
                {
                        assert(styles && styles.length > 0, "Non-leaf style 
beads must have child styles");
                        preprocessStyle();
+                       return gatherLeaves(this);
+               }
+               /**
+                * @royaleignorecoercion 
org.apache.royale.style.stylebeads.ILeafStyleBead
+                */
+               protected function gatherLeaves(parentStyle:IStyleBead):Array
+               {
                        var retVal:Array = [];
                        for each(var style:IStyleBead in styles)
                        {
-                               style.parentStyle = this;
-                               retVal = retVal.concat(style.getLeaves());
+                               style.parentStyle = parentStyle;
+                               if(style.isLeaf)
+                               {
+                                       retVal.push(style);
+                                       var leaf:ILeafStyleBead = style as 
ILeafStyleBead;
+                                       if(!leaf.isDecorated())
+                                               decorateChildStyle(leaf, []);
+                               }
+                               else
+                                       retVal = 
retVal.concat(style.getLeaves());
                        }
-               return retVal;
+                       return retVal;
                }
                /**
                 * Override this method in subclasses to make sure the style is 
normalized

Reply via email to