]> gitweb.factorcode.org Git - factor.git/commitdiff
format-using: avoid creating unused strings
authorAlexander Ilin <alex.ilin@protonmail.com>
Sun, 13 Aug 2023 16:08:50 +0000 (18:08 +0200)
committerAlexander Ilin <alex.ilin@protonmail.com>
Sun, 13 Aug 2023 23:33:37 +0000 (01:33 +0200)
Simply get the length if that's all that is needed.

extra/format-using/format-using.factor

index d88dc47b4aa1a216b16b4cad38de233aee472c80..d57abba0adf43f8cf6caceaf74f6be0680a2448f 100644 (file)
@@ -2,11 +2,12 @@
 ! See https://factorcode.org/license.txt for BSD license.
 USING:
     arrays kernel make math namespaces prettyprint.config sequences
-    sorting splitting.monotonic
+    sorting splitting.monotonic strings
 ;
 IN: format-using
 
-: indent ( -- str ) tab-size get [ CHAR: space ] replicate ; inline
+: indent-length ( -- str ) tab-size get ;
+: indent ( -- str ) indent-length CHAR: space <string> ; inline
 : width-limit ( -- n ) margin get ; inline
 : too-long? ( n -- ? ) width-limit > ; inline
 
@@ -20,7 +21,7 @@ IN: format-using
     [ length ] keep [ length ] map-sum + ;
 
 : costs ( vocabs -- length-on-new-line length-when-added-to-prev-line )
-    joined-length [ indent length + 1 - ] keep ;
+    joined-length [ indent-length + 1 - ] keep ;
 
 : sum-too-long? ( cost1 cost2 -- ? )
     [ first ] [ second ] bi* + too-long? ;
@@ -32,9 +33,9 @@ IN: format-using
     last length 1 > ; inline
 
 : split-subsystem% ( vocabs -- )
-    [ indent length 1 - f ] dip [
+    [ indent-length 1 - f ] dip [
         pick over length + 1 + dup too-long? [
-            drop [ dupd 3array , ] dip [ length indent length + ] keep 1array
+            drop [ dupd 3array , ] dip [ length indent-length + ] keep 1array
         ] [ -rot suffix nipd ] if
     ] each dupd 3array , ;