io.buffers, io.ports: trim some dispatch

For #376. Still some work to do.
db4
Joe Groff 2011-11-09 13:31:02 -08:00
parent 2dd31f4602
commit 63c48aa952
2 changed files with 14 additions and 4 deletions

View File

@ -14,12 +14,12 @@ TUPLE: buffer
disposed ;
: <buffer> ( n -- buffer )
dup malloc 0 0 f buffer boa ;
dup malloc 0 0 f buffer boa ; inline
M: buffer dispose* ptr>> free ;
M: buffer dispose* ptr>> free ; inline
: buffer-reset ( n buffer -- )
swap >>fill 0 >>pos drop ;
swap >>fill 0 >>pos drop ; inline
: buffer-capacity ( buffer -- n )
[ size>> ] [ fill>> ] bi - >fixnum ; inline

View File

@ -34,7 +34,7 @@ INSTANCE: input-port input-stream
M: input-port stream-element-type drop +byte+ ; inline
: <input-port> ( handle -- input-port )
input-port <buffered-port> ;
input-port <buffered-port> ; inline
HOOK: (wait-to-read) io-backend ( port -- )
@ -54,6 +54,8 @@ M: input-port stream-read1
[ buffer>> buffer-read-unsafe ]
} cond ;
HINTS: read-step { fixnum input-port } ;
: prepare-read ( count stream -- count stream )
dup check-disposed [ 0 max >fixnum ] dip ; inline
@ -61,6 +63,10 @@ M: input-port stream-read-partial-unsafe ( n dst port -- count )
[ swap ] dip prepare-read read-step
[ swap [ memcpy ] keep ] [ 2drop 0 ] if* ;
HINTS: M\ input-port stream-read-unsafe
{ fixnum byte-array input-port }
{ fixnum string input-port } ;
:: read-loop ( n-remaining n-read port dst -- n-total )
n-remaining 0 > [
n-remaining port read-step :> ( n-buffered ptr )
@ -86,6 +92,10 @@ M:: input-port stream-read-unsafe ( n dst port -- count )
] if
] [ 0 ] if ;
HINTS: M\ input-port stream-read-unsafe
{ fixnum byte-array input-port }
{ fixnum string input-port } ;
: read-until-step ( separators port -- string/f separator/f )
dup wait-to-read [ 2drop f f ] [ buffer>> buffer-until ] if ;