From ee1eb8bf093ec906924faa57a38493a0e78a0a27 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Fri, 15 Mar 2013 12:15:52 -0700 Subject: [PATCH] io.encodings: this appears to be faster and produce smaller code. --- core/io/encodings/encodings.factor | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/io/encodings/encodings.factor b/core/io/encodings/encodings.factor index 906ccdd9ab..fdb320ff30 100644 --- a/core/io/encodings/encodings.factor +++ b/core/io/encodings/encodings.factor @@ -111,15 +111,18 @@ M: decoder stream-contents* { CHAR: \n [ line-ends\n ] } } case ; inline +! If the stop? branch is taken convert the sbuf to a string ! If sep is present, returns ``string sep'' (string can be "") ! If sep is f, returns ``string f'' or ``f f'' -: (decoder-read-until) ( quot: ( -- char stop? ) -- string/f sep/f ) - [ 100 ] dip over [ push ] curry until - [ "" like ] dip [ f like f ] unless* ; inline +: read-until-loop ( buf quot: ( -- char stop? ) -- string/f sep/f ) + dup call + [ nip [ "" like ] dip [ f like f ] unless* ] + [ pick push read-until-loop ] if ; inline recursive : decoder-read-until ( seps stream encoding -- string/f sep/f ) [ decode-char dup ] 2curry swap [ dupd member? ] curry - [ [ drop f t ] if ] curry compose (decoder-read-until) ; inline + [ [ drop f t ] if ] curry compose + [ 100 ] dip read-until-loop ; inline M: decoder stream-read-until >decoder< decoder-read-until ;