tuned signature, following Bytes.Builder.use;
authorwenzelm
Fri, 28 Jun 2024 11:09:58 +0200
changeset 80440 dfadcfdf8dad
parent 80439 2990f341e0c6
child 80441 c420429fdf4c
tuned signature, following Bytes.Builder.use;
src/Pure/General/html.scala
src/Pure/library.scala
--- a/src/Pure/General/html.scala	Fri Jun 28 00:30:49 2024 +0200
+++ b/src/Pure/General/html.scala	Fri Jun 28 11:09:58 2024 +0200
@@ -224,8 +224,9 @@
 
   def output(text: String): String = {
     val control_blocks = check_control_blocks(List(XML.Text(text)))
-    Library.make_string(output(_, text,
-      control_blocks = control_blocks, hidden = false, permissive = true))
+    Library.string_builder() { builder =>
+      output(builder, text, control_blocks = control_blocks, hidden = false, permissive = true)
+    }
   }
 
 
@@ -259,7 +260,9 @@
   }
 
   def output(body: XML.Body, hidden: Boolean, structural: Boolean): String =
-    Library.make_string(output(_, body, hidden, structural), capacity = XML.text_length(body) * 2)
+    Library.string_builder(hint = XML.text_length(body) * 2) { builder =>
+      output(builder, body, hidden, structural)
+    }
 
   def output(tree: XML.Tree, hidden: Boolean, structural: Boolean): String =
     output(List(tree), hidden, structural)
--- a/src/Pure/library.scala	Fri Jun 28 00:30:49 2024 +0200
+++ b/src/Pure/library.scala	Fri Jun 28 11:09:58 2024 +0200
@@ -143,10 +143,10 @@
 
   /* strings */
 
-  def make_string(f: StringBuilder => Unit, capacity: Int = 16): String = {
-    val s = new StringBuilder(capacity)
-    f(s)
-    s.toString
+  def string_builder(hint: Int = 0)(body: StringBuilder => Unit): String = {
+    val builder = new StringBuilder(if (hint <= 0) 16 else hint)
+    body(builder)
+    builder.toString
   }
 
   def try_unprefix(prfx: String, s: String): Option[String] =