io.binary.fast: adding fast alien version of >le and >be.
parent
714d986326
commit
48c6bba132
|
@ -7,7 +7,7 @@ IN: endian
|
||||||
SINGLETONS: big-endian little-endian ;
|
SINGLETONS: big-endian little-endian ;
|
||||||
|
|
||||||
: compute-native-endianness ( -- class )
|
: compute-native-endianness ( -- class )
|
||||||
1 int <ref> char deref 0 = big-endian little-endian ? ;
|
1 int <ref> char deref 0 = big-endian little-endian ? ; foldable
|
||||||
|
|
||||||
SYMBOL: native-endianness
|
SYMBOL: native-endianness
|
||||||
native-endianness [ compute-native-endianness ] initialize
|
native-endianness [ compute-native-endianness ] initialize
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
! Copyright (C) 2011 Doug Coleman.
|
! Copyright (C) 2011 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: combinators combinators.smart fry kernel macros math
|
USING: alien.data combinators combinators.smart endian fry
|
||||||
math.ranges sequences sequences.generalizations io.binary
|
io.binary kernel locals macros math math.ranges sequences
|
||||||
locals ;
|
sequences.generalizations ;
|
||||||
|
QUALIFIED-WITH: alien.c-types c
|
||||||
RENAME: be> io.binary => slow-be>
|
RENAME: be> io.binary => slow-be>
|
||||||
RENAME: le> io.binary => slow-le>
|
RENAME: le> io.binary => slow-le>
|
||||||
|
RENAME: >be io.binary => >slow-be
|
||||||
|
RENAME: >le io.binary => >slow-le
|
||||||
IN: io.binary.fast
|
IN: io.binary.fast
|
||||||
|
|
||||||
ERROR: bad-length bytes n ;
|
ERROR: bad-length bytes n ;
|
||||||
|
@ -57,3 +60,23 @@ MACRO: reassemble-le ( n -- quot ) le-range reassemble-bytes ;
|
||||||
{ 8 [ 8le> ] }
|
{ 8 [ 8le> ] }
|
||||||
[ drop slow-le> ]
|
[ drop slow-le> ]
|
||||||
} case ;
|
} case ;
|
||||||
|
|
||||||
|
: >le ( x n -- bytes )
|
||||||
|
compute-native-endianness little-endian = [
|
||||||
|
{
|
||||||
|
{ 2 [ c:short <ref> ] }
|
||||||
|
{ 4 [ c:int <ref> ] }
|
||||||
|
{ 8 [ c:longlong <ref> ] }
|
||||||
|
[ >slow-le ]
|
||||||
|
} case
|
||||||
|
] [ >slow-le ] if ;
|
||||||
|
|
||||||
|
: >be ( x n -- bytes )
|
||||||
|
compute-native-endianness big-endian = [
|
||||||
|
{
|
||||||
|
{ 2 [ c:short <ref> ] }
|
||||||
|
{ 4 [ c:int <ref> ] }
|
||||||
|
{ 8 [ c:longlong <ref> ] }
|
||||||
|
[ >slow-be ]
|
||||||
|
} case
|
||||||
|
] [ >slow-be ] if ;
|
||||||
|
|
Loading…
Reference in New Issue