From 757889167a2deb86137e5289e39cd57c46426d0a Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 11 Oct 2011 19:36:22 -0700 Subject: [PATCH] Optimize byte-reverse macro in alien.endian -- it was shifting each byte to the 0th bit place, bitand-ing it with HEX: ff, then shifting it to its final destination -- now we immediately shift to the proper location and bitand with the proper bitmask. --- basis/alien/endian/endian.factor | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/basis/alien/endian/endian.factor b/basis/alien/endian/endian.factor index bc2919bb6e..b905e4b66b 100644 --- a/basis/alien/endian/endian.factor +++ b/basis/alien/endian/endian.factor @@ -18,13 +18,21 @@ ERROR: invalid-signed-conversion n ; [ invalid-signed-conversion ] } case ; inline + + MACRO: byte-reverse ( n signed? -- quot ) [ drop [ dup iota [ [ 1 + - -8 * ] [ nip 8 * ] 2bi - '[ _ shift HEX: ff bitand _ shift ] + [ + ] [ nip byte-mask ] 2bi + '[ _ shift _ bitand ] ] with map ] [ 1 - [ bitor ] n*quot ] bi ] [