]> gitweb.factorcode.org Git - factor.git/commitdiff
splitting: string-lines is optimized for strings. revert my previous slowdown of...
authorDoug Coleman <doug.coleman@gmail.com>
Wed, 6 Apr 2016 04:16:27 +0000 (21:16 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 6 Apr 2016 04:17:43 +0000 (21:17 -0700)
core/splitting/splitting.factor

index ac75d387b7fed4d29d99880bcf03916cfa8a5dd7..5a413b916ec6572adfe5f1cfeea37c4927f03a19 100644 (file)
@@ -106,7 +106,12 @@ PRIVATE>
         [ pick subseq ] keep swap
     ] map 2nip ;
 
-: string-lines ( seq -- seq' )
+! string-lines uses string-nth-fast which is 50% faster over
+! nth-unsafe. be careful when changing the definition so that
+! you don't unoptimize it.
+GENERIC: string-lines ( seq -- seq' )
+
+M: string string-lines
     [ V{ } clone 0 ] dip [ 2dup bounds-check? ] [
         2dup [ "\r\n" member? ] find-from swapd [
             over [ [ nip length ] keep ] unless
@@ -114,4 +119,6 @@ PRIVATE>
         ] dip CHAR: \r eq? [
             2dup ?nth CHAR: \n eq? [ [ 1 + ] dip ] when
         ] when
-    ] while 2drop { } like ;
\ No newline at end of file
+    ] while 2drop { } like ;
+
+M: sbuf string-lines "" like string-lines ;