parent
2dd31f4602
commit
63c48aa952
|
@ -14,12 +14,12 @@ TUPLE: buffer
|
||||||
disposed ;
|
disposed ;
|
||||||
|
|
||||||
: <buffer> ( n -- buffer )
|
: <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 -- )
|
: buffer-reset ( n buffer -- )
|
||||||
swap >>fill 0 >>pos drop ;
|
swap >>fill 0 >>pos drop ; inline
|
||||||
|
|
||||||
: buffer-capacity ( buffer -- n )
|
: buffer-capacity ( buffer -- n )
|
||||||
[ size>> ] [ fill>> ] bi - >fixnum ; inline
|
[ size>> ] [ fill>> ] bi - >fixnum ; inline
|
||||||
|
|
|
@ -34,7 +34,7 @@ INSTANCE: input-port input-stream
|
||||||
M: input-port stream-element-type drop +byte+ ; inline
|
M: input-port stream-element-type drop +byte+ ; inline
|
||||||
|
|
||||||
: <input-port> ( handle -- input-port )
|
: <input-port> ( handle -- input-port )
|
||||||
input-port <buffered-port> ;
|
input-port <buffered-port> ; inline
|
||||||
|
|
||||||
HOOK: (wait-to-read) io-backend ( port -- )
|
HOOK: (wait-to-read) io-backend ( port -- )
|
||||||
|
|
||||||
|
@ -54,6 +54,8 @@ M: input-port stream-read1
|
||||||
[ buffer>> buffer-read-unsafe ]
|
[ buffer>> buffer-read-unsafe ]
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
||||||
|
HINTS: read-step { fixnum input-port } ;
|
||||||
|
|
||||||
: prepare-read ( count stream -- count stream )
|
: prepare-read ( count stream -- count stream )
|
||||||
dup check-disposed [ 0 max >fixnum ] dip ; inline
|
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 ] dip prepare-read read-step
|
||||||
[ swap [ memcpy ] keep ] [ 2drop 0 ] if* ;
|
[ 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 )
|
:: read-loop ( n-remaining n-read port dst -- n-total )
|
||||||
n-remaining 0 > [
|
n-remaining 0 > [
|
||||||
n-remaining port read-step :> ( n-buffered ptr )
|
n-remaining port read-step :> ( n-buffered ptr )
|
||||||
|
@ -86,6 +92,10 @@ M:: input-port stream-read-unsafe ( n dst port -- count )
|
||||||
] if
|
] if
|
||||||
] [ 0 ] 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 )
|
: read-until-step ( separators port -- string/f separator/f )
|
||||||
dup wait-to-read [ 2drop f f ] [ buffer>> buffer-until ] if ;
|
dup wait-to-read [ 2drop f f ] [ buffer>> buffer-until ] if ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue