From c6bbeffe543f8b3c8b319e2276afc309c96801f6 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Fri, 13 Jul 2012 18:24:45 -0700 Subject: [PATCH] splitting: string-lines is 30-70% faster. --- core/splitting/splitting.factor | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/core/splitting/splitting.factor b/core/splitting/splitting.factor index 58762dd9ce..305e06c467 100644 --- a/core/splitting/splitting.factor +++ b/core/splitting/splitting.factor @@ -91,15 +91,23 @@ PRIVATE> : split*-when ( ... seq quot: ( ... elt -- ... ? ) -- ... pieces ) [ split*, ] { } make ; inline + + GENERIC: string-lines ( str -- seq ) M: string string-lines - dup "\r\n" intersects? [ - "\n" split [ - but-last-slice [ - "\r" ?tail drop "\r" split - ] map - ] keep last "\r" split suffix concat + dup crlf? [ + "\n" split + [ but-last-slice [ "\r" ?tail drop "\r" split ] map! drop ] + [ [ length 1 - ] keep [ "\r" split ] change-nth ] + [ concat ] + tri ] [ 1array ] if ;