From 1f7bf0d6abf9f956e7d1592233f4ab62e2bac32a Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 5 Apr 2016 21:16:27 -0700 Subject: [PATCH] splitting: string-lines is optimized for strings. revert my previous slowdown of 50% or so. add a note so this won't happen again. oops. --- core/splitting/splitting.factor | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/splitting/splitting.factor b/core/splitting/splitting.factor index ac75d387b7..5a413b916e 100644 --- a/core/splitting/splitting.factor +++ b/core/splitting/splitting.factor @@ -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 ;