kill noncopying-reader mixin, stream-read generic
Now that all streams have been updated to implement the stream-read-unsafe protocol, take out the noncopying-reader shim. Turn stream-read and stream-read-partial into plain functions over the -unsafe generics.db4
parent
cd00603e2d
commit
6f12322bda
|
@ -93,7 +93,6 @@ M: bad-byte-array-length summary
|
|||
: malloc-string ( string encoding -- alien )
|
||||
string>alien malloc-byte-array ;
|
||||
|
||||
INSTANCE: memory-stream noncopying-reader
|
||||
M:: memory-stream stream-read-unsafe ( n buf stream -- count )
|
||||
stream alien>> :> src
|
||||
buf src n memcpy
|
||||
|
|
|
@ -29,7 +29,6 @@ TUPLE: buffered-port < port { buffer buffer } ;
|
|||
default-buffer-size get <buffer> >>buffer ; inline
|
||||
|
||||
TUPLE: input-port < buffered-port ;
|
||||
INSTANCE: input-port noncopying-reader
|
||||
|
||||
M: input-port stream-element-type drop +byte+ ; inline
|
||||
|
||||
|
|
|
@ -86,12 +86,6 @@ M: limited-stream stream-read1
|
|||
1 swap
|
||||
[ nip stream-read1 ] maybe-read ;
|
||||
|
||||
M: limited-stream stream-read
|
||||
[ stream-read ] maybe-read ;
|
||||
|
||||
M: limited-stream stream-read-partial
|
||||
[ stream-read-partial ] maybe-read ;
|
||||
|
||||
M: limited-stream stream-read-unsafe
|
||||
[ stream-read-unsafe ] maybe-read-unsafe ;
|
||||
|
||||
|
|
|
@ -13,8 +13,6 @@ M: null-reader stream-element-type drop +byte+ ;
|
|||
M: null-reader stream-readln drop f ;
|
||||
M: null-reader stream-read1 drop f ;
|
||||
M: null-reader stream-read-until 2drop f f ;
|
||||
M: null-reader stream-read 2drop f ;
|
||||
M: null-reader stream-read-partial 2drop f ;
|
||||
M: null-reader stream-read-unsafe 3drop 0 ;
|
||||
M: null-reader stream-read-partial-unsafe 3drop 0 ;
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ IN: io.streams.string
|
|||
|
||||
! Readers
|
||||
TUPLE: string-reader { underlying string read-only } { i array-capacity } ;
|
||||
INSTANCE: string-reader noncopying-reader
|
||||
|
||||
M: string-reader stream-element-type drop +character+ ;
|
||||
M: string-reader stream-read-partial-unsafe sequence-read-unsafe ;
|
||||
|
|
|
@ -20,14 +20,6 @@ M:: throws-on-eof-stream stream-read1 ( stream -- obj )
|
|||
stream stream>> stream-read1
|
||||
[ 1 stream \ read1 stream-exhausted ] unless* ;
|
||||
|
||||
M:: throws-on-eof-stream stream-read ( n stream -- seq )
|
||||
n stream stream>> stream-read
|
||||
dup length n = [ n stream \ read stream-exhausted ] unless ;
|
||||
|
||||
M:: throws-on-eof-stream stream-read-partial ( n stream -- seq )
|
||||
n stream stream>> stream-read-partial
|
||||
[ n stream \ read-partial stream-exhausted ] unless* ;
|
||||
|
||||
M:: throws-on-eof-stream stream-read-unsafe ( n buf stream -- count )
|
||||
n buf stream stream>> stream-read-unsafe
|
||||
dup n = [ n stream \ stream-read-unsafe stream-exhausted ] unless ;
|
||||
|
|
|
@ -23,7 +23,6 @@ IN: ui.tools.listener
|
|||
! evaluate-input resumes the thread.
|
||||
TUPLE: interactor < source-editor
|
||||
output history flag mailbox thread waiting token-model word-model popup ;
|
||||
INSTANCE: interactor noncopying-reader
|
||||
|
||||
: register-self ( interactor -- )
|
||||
<mailbox> >>mailbox
|
||||
|
|
|
@ -26,7 +26,6 @@ GENERIC: <decoder> ( stream encoding -- newstream )
|
|||
CONSTANT: replacement-char HEX: fffd
|
||||
|
||||
TUPLE: decoder { stream read-only } { code read-only } { cr boolean } ;
|
||||
INSTANCE: decoder noncopying-reader
|
||||
|
||||
ERROR: decode-error ;
|
||||
|
||||
|
|
|
@ -9,11 +9,9 @@ SYMBOLS: +byte+ +character+ ;
|
|||
GENERIC: stream-element-type ( stream -- type )
|
||||
|
||||
GENERIC: stream-read1 ( stream -- elt )
|
||||
GENERIC: stream-read-unsafe ( n buf stream -- n' )
|
||||
GENERIC: stream-read ( n stream -- seq )
|
||||
GENERIC: stream-read-unsafe ( n buf stream -- count )
|
||||
GENERIC: stream-read-until ( seps stream -- seq sep/f )
|
||||
GENERIC: stream-read-partial-unsafe ( n buf stream -- n' )
|
||||
GENERIC: stream-read-partial ( n stream -- seq )
|
||||
GENERIC: stream-read-partial-unsafe ( n buf stream -- count )
|
||||
GENERIC: stream-readln ( stream -- str/f )
|
||||
|
||||
GENERIC: stream-write1 ( elt stream -- )
|
||||
|
@ -37,9 +35,7 @@ SYMBOL: error-stream
|
|||
|
||||
: readln ( -- str/f ) input-stream get stream-readln ;
|
||||
: read1 ( -- elt ) input-stream get stream-read1 ;
|
||||
: read ( n -- seq ) input-stream get stream-read ;
|
||||
: read-until ( seps -- seq sep/f ) input-stream get stream-read-until ;
|
||||
: read-partial ( n -- seq ) input-stream get stream-read-partial ;
|
||||
: tell-input ( -- n ) input-stream get stream-tell ;
|
||||
: tell-output ( -- n ) output-stream get stream-tell ;
|
||||
: seek-input ( n seek-type -- ) input-stream get stream-seek ;
|
||||
|
@ -93,8 +89,24 @@ SYMBOL: error-stream
|
|||
{ +character+ [ SBUF" " ] }
|
||||
} case ; inline
|
||||
|
||||
: (new-sequence-for-stream) ( n stream -- seq )
|
||||
stream-exemplar new-sequence ; inline
|
||||
|
||||
: (read-into-new) ( n stream quot -- byte-array/f )
|
||||
[ 2dup (new-sequence-for-stream) swap ] dip curry keep
|
||||
over 0 = [ 2drop f ] [ resize ] if ; inline
|
||||
|
||||
PRIVATE>
|
||||
|
||||
: stream-read ( n stream -- seq/f )
|
||||
[ stream-read-unsafe ] (read-into-new) ; inline
|
||||
|
||||
: stream-read-partial ( n stream -- seq/f )
|
||||
[ stream-read-partial-unsafe ] (read-into-new) ; inline
|
||||
|
||||
: read ( n -- seq ) input-stream get stream-read ;
|
||||
: read-partial ( n -- seq ) input-stream get stream-read-partial ;
|
||||
|
||||
: each-stream-line ( ... stream quot: ( ... line -- ... ) -- ... )
|
||||
swap [ stream-readln ] curry each-morsel ; inline
|
||||
|
||||
|
@ -137,20 +149,3 @@ PRIVATE>
|
|||
: stream-copy ( in out -- )
|
||||
[ [ [ write ] each-block ] with-output-stream ]
|
||||
curry with-input-stream ;
|
||||
|
||||
! Implement stream-read and stream-read-partial in terms of -unsafe
|
||||
|
||||
MIXIN: noncopying-reader
|
||||
|
||||
: (new-sequence-for-stream) ( n stream -- seq )
|
||||
stream-exemplar new-sequence ; inline
|
||||
|
||||
: (read-into-new) ( n stream quot -- byte-array/f )
|
||||
[ 2dup (new-sequence-for-stream) swap ] dip curry keep
|
||||
over 0 = [ 2drop f ] [ resize ] if ; inline
|
||||
|
||||
M: noncopying-reader stream-read
|
||||
[ stream-read-unsafe ] (read-into-new) ; inline
|
||||
|
||||
M: noncopying-reader stream-read-partial
|
||||
[ stream-read-partial-unsafe ] (read-into-new) ; inline
|
||||
|
|
|
@ -15,7 +15,6 @@ M: byte-vector stream-element-type drop +byte+ ;
|
|||
dup encoder? [ stream>> ] when >byte-array ; inline
|
||||
|
||||
TUPLE: byte-reader { underlying byte-array read-only } { i array-capacity } ;
|
||||
INSTANCE: byte-reader noncopying-reader
|
||||
|
||||
M: byte-reader stream-element-type drop +byte+ ;
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ M: c-writer stream-write
|
|||
M: c-writer stream-flush dup check-disposed handle>> fflush ;
|
||||
|
||||
TUPLE: c-reader < c-stream ;
|
||||
INSTANCE: c-reader noncopying-reader
|
||||
|
||||
: <c-reader> ( handle -- stream ) c-reader new-c-stream ;
|
||||
|
||||
|
@ -49,7 +48,6 @@ M: c-reader stream-element-type drop +byte+ ;
|
|||
M: c-reader stream-read-unsafe dup check-disposed handle>> fread-unsafe ;
|
||||
|
||||
M: c-reader stream-read-partial-unsafe stream-read-unsafe ;
|
||||
M: c-reader stream-read-partial stream-read ;
|
||||
|
||||
M: c-reader stream-read1 dup check-disposed handle>> fgetc ;
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ vectors ;
|
|||
IN: io.streams.peek
|
||||
|
||||
TUPLE: peek-stream stream peeked ;
|
||||
INSTANCE: peek-stream noncopying-reader
|
||||
|
||||
M: peek-stream dispose stream>> dispose ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue