SVGHMI: Remove recursive walk in parsed widget to find unique type and use xsl:key instead. svghmi
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Tue, 02 Feb 2021 10:43:43 +0100
branchsvghmi
changeset 3120 7ecaefe38f6f
parent 3119 17a9c7a334f7
child 3123 f8cba959553f
SVGHMI: Remove recursive walk in parsed widget to find unique type and use xsl:key instead.
svghmi/widgets_common.ysl2
--- a/svghmi/widgets_common.ysl2	Tue Jan 26 11:17:08 2021 +0100
+++ b/svghmi/widgets_common.ysl2	Tue Feb 02 10:43:43 2021 +0100
@@ -63,27 +63,6 @@
     |   })`if "position()!=last()" > ,`
 }
 
-def "func:unique_types" {
-    param "elts_with_type";
-    choose {
-        when "count($elts_with_type) > 1" {
-            const "prior_results","func:unique_types($elts_with_type[position()!=last()])";
-            choose {
-                when "$elts_with_type[last()][@type = $prior_results/@type]"{
-                    // type already in
-                    result "$prior_results";
-                }
-                otherwise {
-                    result "$prior_results | $elts_with_type[last()]";
-                }
-            }
-        }
-        otherwise {
-            result "$elts_with_type";
-        }
-    }
-}
-
 emit "preamble:local-variable-indexes" {
     ||
     let hmi_locals = {};
@@ -276,8 +255,15 @@
     ||
 }
 
+const "excluded_types", "str:split('Page Lang VarInit')";
+
+// Key to filter unique types
+key "TypesKey", "widget", "@type";
+
 emit "declarations:hmi-classes" {
-    const "used_widget_types", "func:unique_types($parsed_widgets/widget)";
+    const "used_widget_types", """$parsed_widgets/widget[
+                                    generate-id() = generate-id(key('TypesKey', @type)) and 
+                                    not(@type = $excluded_types)]""";
     apply "$used_widget_types", mode="widget_class";
 }
 
@@ -288,7 +274,6 @@
 }
 ||
 
-const "excluded_types", "str:split('Page Lang VarInit')";
 const "included_ids","$parsed_widgets/widget[not(@type = $excluded_types) and not(@id = $discardable_elements/@id)]/@id";
 
 emit "declarations:hmi-elements" {