From a2c241baea679d59e8e118943ced7b4c448cc628 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Thu, 21 Mar 2013 17:39:34 -0700 Subject: [PATCH] io.binary: faster >be. --- core/io/binary/binary.factor | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/core/io/binary/binary.factor b/core/io/binary/binary.factor index 793fe0686a..4d0c87e7ed 100644 --- a/core/io/binary/binary.factor +++ b/core/io/binary/binary.factor @@ -4,26 +4,32 @@ USING: kernel math sequences ; IN: io.binary : le> ( seq -- x ) dup length iota 0 [ 8 * shift + ] 2reduce ; + : be> ( seq -- x ) 0 [ [ 8 shift ] dip + ] reduce ; : mask-byte ( x -- y ) 0xff bitand ; inline : nth-byte ( x n -- b ) -8 * shift mask-byte ; inline -: >le ( x n -- byte-array ) iota [ nth-byte ] with B{ } map-as ; -: >be ( x n -- byte-array ) >le reverse! ; + + +: >le ( x n -- byte-array ) iota map-bytes ; + +: >be ( x n -- byte-array ) iota map-bytes ; : d>w/w ( d -- w1 w2 ) - [ 0xffffffff bitand ] - [ -32 shift 0xffffffff bitand ] bi ; + [ 0xffffffff bitand ] [ -32 shift 0xffffffff bitand ] bi ; : w>h/h ( w -- h1 h2 ) - [ 0xffff bitand ] - [ -16 shift 0xffff bitand ] bi ; + [ 0xffff bitand ] [ -16 shift 0xffff bitand ] bi ; : h>b/b ( h -- b1 b2 ) - [ mask-byte ] - [ -8 shift mask-byte ] bi ; + [ mask-byte ] [ -8 shift mask-byte ] bi ; : signed-le> ( bytes -- x ) [ le> ] [ length 8 * 1 - 2^ 1 - ] bi