minor performance tuning, following Isabelle/Scala;
authorwenzelm
Mon, 09 Sep 2024 23:50:58 +0200
changeset 80838 aaf9e8a392cc
parent 80837 ddc062eac871
child 80839 b11bd8af381d
minor performance tuning, following Isabelle/Scala;
src/Pure/PIDE/xml.ML
src/Pure/PIDE/xml_type.ML
--- a/src/Pure/PIDE/xml.ML	Mon Sep 09 23:47:08 2024 +0200
+++ b/src/Pure/PIDE/xml.ML	Mon Sep 09 23:50:58 2024 +0200
@@ -96,8 +96,8 @@
 (* text content *)
 
 fun add_content tree =
-  (case unwrap_elem tree of
-    SOME (_, ts) => fold add_content ts
+  (case unwrap_elem_body tree of
+    SOME ts => fold add_content ts
   | NONE =>
       (case tree of
         Elem (_, ts) => fold add_content ts
--- a/src/Pure/PIDE/xml_type.ML	Mon Sep 09 23:47:08 2024 +0200
+++ b/src/Pure/PIDE/xml_type.ML	Mon Sep 09 23:50:58 2024 +0200
@@ -16,6 +16,7 @@
   val xml_bodyN: string
   val wrap_elem: ((string * attributes) * body) * body -> tree
   val unwrap_elem: tree -> (((string * attributes) * body) * body) option
+  val unwrap_elem_body: tree -> body option
   val content_of: body -> string
 end
 
@@ -45,14 +46,19 @@
       then SOME (((a, atts), body1), body2) else NONE
   | unwrap_elem _ = NONE;
 
+fun unwrap_elem_body (Elem ((name, (n, _) :: _), Elem ((name', []), _) :: body)) =
+      if name = xml_elemN andalso n = xml_nameN andalso name' = xml_bodyN
+      then SOME body else NONE
+  | unwrap_elem_body _ = NONE;
+
 
 (* text content *)
 
 fun add_contents [] res = res
   | add_contents (t :: ts) res = add_contents ts (add_content t res)
 and add_content tree res =
-  (case unwrap_elem tree of
-    SOME (_, ts) => add_contents ts res
+  (case unwrap_elem_body tree of
+    SOME ts => add_contents ts res
   | NONE =>
       (case tree of
         Elem (_, ts) => add_contents ts res