diff --git a/basis/checksums/superfast/superfast.factor b/basis/checksums/superfast/superfast.factor index 97b3b8e433..c883194e85 100644 --- a/basis/checksums/superfast/superfast.factor +++ b/basis/checksums/superfast/superfast.factor @@ -1,10 +1,9 @@ ! Copyright (C) 2013 John Benediktsson. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors alien alien.data byte-arrays checksums -combinators fry grouping io.binary kernel math math.bitwise -math.ranges sequences sequences.private ; -QUALIFIED-WITH: alien.c-types c +USING: accessors alien alien.c-types alien.data byte-arrays +checksums combinators fry grouping io.binary kernel math +math.bitwise math.ranges sequences sequences.private ; IN: checksums.superfast @@ -15,23 +14,21 @@ C: superfast : 32-bit ( n -- n' ) 32 on-bits mask ; inline +: (main-loop) ( hash m n -- hash' ) + [ + ] [ 11 shift dupd bitxor ] bi* + [ 16 shift ] [ bitxor ] bi* 32-bit + [ -11 shift ] [ + ] bi ; inline + : main-loop ( seq hash -- seq hash' ) over byte-array? little-endian? and [ - [ 0 over length 4 - 4 ] dip - [ - pick - [ c:short deref ] - [ [ 2 + ] dip c:short deref ] 2bi - [ + ] [ 11 shift dupd bitxor ] bi* - [ 16 shift ] [ bitxor ] bi* 32-bit - [ -11 shift ] [ + ] bi + [ 0 over length 4 - 4 ] dip [ + pick int deref + [ 16 on-bits mask ] [ -16 shift ] bi + (main-loop) ] reduce ] [ [ dup length 4 mod dupd head-slice* 4 ] dip [ - 2 cut-slice - [ le> + ] [ le> 11 shift dupd bitxor ] bi* - [ 16 shift ] [ bitxor ] bi* 32-bit - [ -11 shift ] [ + ] bi + 2 cut-slice [ le> ] bi@ (main-loop) ] reduce ] if ; inline