specialized-arrays: generate slightly more efficient byte-array>T-array words
parent
6501480a0e
commit
08a80e5ba2
|
@ -1,4 +1,4 @@
|
||||||
! Copyright (C) 2008, 2009 Slava Pestov.
|
! Copyright (C) 2008, 2010 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors alien alien.c-types alien.data alien.parser
|
USING: accessors alien alien.c-types alien.data alien.parser
|
||||||
assocs byte-arrays classes compiler.units functors kernel lexer
|
assocs byte-arrays classes compiler.units functors kernel lexer
|
||||||
|
@ -19,6 +19,11 @@ ERROR: bad-byte-array-length byte-array type ;
|
||||||
M: bad-byte-array-length summary
|
M: bad-byte-array-length summary
|
||||||
drop "Byte array length doesn't divide type width" ;
|
drop "Byte array length doesn't divide type width" ;
|
||||||
|
|
||||||
|
ERROR: not-a-byte-array alien ;
|
||||||
|
|
||||||
|
M: not-a-byte-array summary
|
||||||
|
drop "Not a byte array" ;
|
||||||
|
|
||||||
: (underlying) ( n c-type -- array )
|
: (underlying) ( n c-type -- array )
|
||||||
heap-size * (byte-array) ; inline
|
heap-size * (byte-array) ; inline
|
||||||
|
|
||||||
|
@ -61,9 +66,11 @@ TUPLE: A
|
||||||
[ \ T heap-size calloc ] keep <direct-A> ; inline
|
[ \ T heap-size calloc ] keep <direct-A> ; inline
|
||||||
|
|
||||||
: byte-array>A ( byte-array -- specialized-array )
|
: byte-array>A ( byte-array -- specialized-array )
|
||||||
>c-ptr dup length \ T heap-size /mod 0 =
|
>c-ptr dup byte-array? [
|
||||||
[ drop \ T bad-byte-array-length ] unless
|
dup length \ T heap-size /mod 0 =
|
||||||
<direct-A> ; inline
|
[ <direct-A> ]
|
||||||
|
[ drop \ T bad-byte-array-length ] if
|
||||||
|
] [ not-a-byte-array ] if ; inline
|
||||||
|
|
||||||
M: A clone [ underlying>> clone ] [ length>> ] bi <direct-A> ; inline
|
M: A clone [ underlying>> clone ] [ length>> ] bi <direct-A> ; inline
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue