io.streams.memory: implement stream-read-unsafe
(The actual method is in alien.data due to bootstrap load order issues.)db4
parent
d5f4b6f155
commit
b79d7158be
|
@ -2,7 +2,7 @@
|
||||||
USING: accessors alien alien.arrays alien.c-types alien.strings
|
USING: accessors alien alien.arrays alien.c-types alien.strings
|
||||||
arrays byte-arrays combinators combinators.short-circuit
|
arrays byte-arrays combinators combinators.short-circuit
|
||||||
cpu.architecture fry generalizations io io.streams.memory kernel
|
cpu.architecture fry generalizations io io.streams.memory kernel
|
||||||
libc macros math math.functions parser sequences
|
libc locals macros math math.functions parser sequences
|
||||||
stack-checker.dependencies summary words ;
|
stack-checker.dependencies summary words ;
|
||||||
QUALIFIED: math
|
QUALIFIED: math
|
||||||
IN: alien.data
|
IN: alien.data
|
||||||
|
@ -93,11 +93,13 @@ M: bad-byte-array-length summary
|
||||||
: malloc-string ( string encoding -- alien )
|
: malloc-string ( string encoding -- alien )
|
||||||
string>alien malloc-byte-array ;
|
string>alien malloc-byte-array ;
|
||||||
|
|
||||||
M: memory-stream stream-read
|
INSTANCE: memory-stream noncopying-reader
|
||||||
[
|
M:: memory-stream stream-read-unsafe ( n buf stream -- count )
|
||||||
[ index>> ] [ alien>> ] bi <displaced-alien>
|
stream alien>> :> src
|
||||||
swap memory>byte-array
|
buf src n memcpy
|
||||||
] [ [ + ] change-index drop ] 2bi ;
|
n src <displaced-alien> stream alien<<
|
||||||
|
n ; inline
|
||||||
|
M: memory-stream stream-read-partial-unsafe stream-read-unsafe ; inline
|
||||||
|
|
||||||
M: value-type c-type-rep drop int-rep ;
|
M: value-type c-type-rep drop int-rep ;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
! (c)2011 Joe Groff bsd license
|
||||||
|
USING: alien.data destructors io io.streams.memory kernel libc
|
||||||
|
tools.test ;
|
||||||
|
IN: io.streams.memory.tests
|
||||||
|
|
||||||
|
{ 1 2 3 } [
|
||||||
|
B{ 1 2 3 } <memory-stream>
|
||||||
|
[ stream-read1 ] [ stream-read1 ] [ stream-read1 ] tri
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
{ 1 2 3 } [
|
||||||
|
[
|
||||||
|
B{ 1 2 3 } malloc-byte-array &free <memory-stream>
|
||||||
|
[ stream-read1 ] [ stream-read1 ] [ stream-read1 ] tri
|
||||||
|
] with-destructors
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
{ B{ 1 2 3 } B{ 4 5 6 7 8 } } [
|
||||||
|
B{ 1 2 3 4 5 6 7 8 } <memory-stream>
|
||||||
|
[ 3 swap stream-read ] [ 5 swap stream-read ] bi
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
{ B{ 1 2 3 } B{ 4 5 6 7 8 } } [
|
||||||
|
[
|
||||||
|
B{ 1 2 3 4 5 6 7 8 } malloc-byte-array &free <memory-stream>
|
||||||
|
[ 3 swap stream-read ] [ 5 swap stream-read ] bi
|
||||||
|
] with-destructors
|
||||||
|
] unit-test
|
|
@ -3,13 +3,13 @@
|
||||||
USING: kernel accessors alien alien.accessors math io ;
|
USING: kernel accessors alien alien.accessors math io ;
|
||||||
IN: io.streams.memory
|
IN: io.streams.memory
|
||||||
|
|
||||||
TUPLE: memory-stream alien index ;
|
TUPLE: memory-stream alien ;
|
||||||
|
|
||||||
: <memory-stream> ( alien -- stream )
|
: <memory-stream> ( alien -- stream )
|
||||||
0 memory-stream boa ;
|
memory-stream boa ;
|
||||||
|
|
||||||
M: memory-stream stream-element-type drop +byte+ ;
|
M: memory-stream stream-element-type drop +byte+ ;
|
||||||
|
|
||||||
M: memory-stream stream-read1
|
M: memory-stream stream-read1
|
||||||
[ [ alien>> ] [ index>> ] bi alien-unsigned-1 ]
|
[ 1 over <displaced-alien> ] change-alien drop
|
||||||
[ [ 1 + ] change-index drop ] bi ;
|
0 alien-unsigned-1 ; inline
|
||||||
|
|
Loading…
Reference in New Issue