splitting: string-lines is 30-70% faster.

db4
John Benediktsson 2012-07-13 18:24:45 -07:00
parent 6f20c2fa61
commit 646e9db251
1 changed files with 14 additions and 6 deletions

View File

@ -91,15 +91,23 @@ PRIVATE>
: split*-when ( ... seq quot: ( ... elt -- ... ? ) -- ... pieces ) : split*-when ( ... seq quot: ( ... elt -- ... ? ) -- ... pieces )
[ split*, ] { } make ; inline [ split*, ] { } make ; inline
<PRIVATE
: crlf? ( str -- ? )
[ dup CHAR: \r = [ drop t ] [ CHAR: \n = ] if ] find drop ;
inline
PRIVATE>
GENERIC: string-lines ( str -- seq ) GENERIC: string-lines ( str -- seq )
M: string string-lines M: string string-lines
dup "\r\n" intersects? [ dup crlf? [
"\n" split [ "\n" split
but-last-slice [ [ but-last-slice [ "\r" ?tail drop "\r" split ] map! drop ]
"\r" ?tail drop "\r" split [ [ length 1 - ] keep [ "\r" split ] change-nth ]
] map [ concat ]
] keep last "\r" split suffix concat tri
] [ ] [
1array 1array
] if ; ] if ;