]> gitweb.factorcode.org Git - factor.git/commitdiff
splitting: slightly faster string-lines.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 14 Jul 2012 03:26:07 +0000 (20:26 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 14 Jul 2012 03:26:07 +0000 (20:26 -0700)
core/splitting/splitting.factor

index 305e06c46764be9493abad326027a13853f2b544..69a66eb5fdba5c6c3736f3083b626750ce6352e3 100644 (file)
@@ -104,8 +104,15 @@ GENERIC: string-lines ( str -- seq )
 M: string string-lines
     dup crlf? [
         "\n" split
-        [ but-last-slice [ "\r" ?tail drop "\r" split ] map! drop ]
-        [ [ length 1 - ] keep [ "\r" split ] change-nth ]
+        [
+            but-last-slice [
+                dup ?last CHAR: \r = [ but-last ] when
+                [ CHAR: \r = ] split-when
+            ] map! drop
+        ] [
+            [ length 1 - ] keep
+            [ [ CHAR: \r = ] split-when ] change-nth
+        ]
         [ concat ]
         tri
     ] [