minor performance tuning: avoid concatenation of existing string material;
authorwenzelm
Sun, 10 Nov 2024 13:40:28 +0100
changeset 81422 b6928aa389f7
parent 81421 8c1680ac4160
child 81423 056657540039
minor performance tuning: avoid concatenation of existing string material;
src/Pure/PIDE/command.scala
src/Pure/PIDE/document.scala
--- a/src/Pure/PIDE/command.scala	Sun Nov 10 12:56:38 2024 +0100
+++ b/src/Pure/PIDE/command.scala	Sun Nov 10 13:40:28 2024 +0100
@@ -395,9 +395,6 @@
       markups = Markups.init(Markup_Tree.from_XML(body)))
   }
 
-  def full_source(commands: Iterable[Command]): String =
-    commands.iterator.map(_.source).mkString
-
 
   /* edits and perspective */
 
--- a/src/Pure/PIDE/document.scala	Sun Nov 10 12:56:38 2024 +0100
+++ b/src/Pure/PIDE/document.scala	Sun Nov 10 13:40:28 2024 +0100
@@ -649,8 +649,18 @@
       val nodes2 = blobs.foldLeft(nodes1) { case (ns, (a, b)) => ns + (a -> Node.init_blob(b)) }
       val version1 = Version.make(nodes2)
 
+      val text_edits: List[Text.Edit] = {
+        var offset = 0
+        val result = new mutable.ListBuffer[Text.Edit]
+        for (command <- commands) {
+          result += Text.Edit.insert(offset, command.source)
+          offset += command.source.length
+        }
+        result.toList
+      }
+
       val edits: List[Edit_Text] =
-        List(node_name -> Node.Edits(List(Text.Edit.insert(0, Command.full_source(commands))))) :::
+        List(node_name -> Node.Edits(text_edits)) :::
         blobs.map({ case (a, b) => a -> Node.Blob(b) })
 
       val assign_update: Assign_Update =