checksums: simplify add-checksum-bytes.

db4
John Benediktsson 2014-02-17 18:25:51 -08:00
parent d732a5f208
commit 59677102b6
1 changed files with 7 additions and 5 deletions

View File

@ -7,7 +7,9 @@ IN: checksums
MIXIN: checksum MIXIN: checksum
TUPLE: checksum-state TUPLE: checksum-state
{ bytes-read integer } { block-size integer } { bytes byte-vector } ; { bytes-read integer }
{ block-size integer }
{ bytes byte-vector } ;
: new-checksum-state ( class -- checksum-state ) : new-checksum-state ( class -- checksum-state )
new new
@ -17,7 +19,7 @@ M: checksum-state clone
call-next-method call-next-method
[ clone ] change-bytes ; [ clone ] change-bytes ;
GENERIC: initialize-checksum-state ( class -- checksum-state ) GENERIC: initialize-checksum-state ( checksum -- checksum-state )
GENERIC: checksum-block ( bytes checksum -- ) GENERIC: checksum-block ( bytes checksum -- )
@ -27,9 +29,9 @@ GENERIC: get-checksum ( checksum -- value )
over bytes>> [ push-all ] keep over bytes>> [ push-all ] keep
[ dup length pick block-size>> >= ] [ dup length pick block-size>> >= ]
[ [
over block-size>> cut-slice [ >byte-array ] dip [ over block-size>> cut-slice [
over [ checksum-block ] >byte-array over checksum-block
[ [ ] [ block-size>> ] bi [ + ] curry change-bytes-read drop ] bi [ block-size>> ] keep [ + ] change-bytes-read
] dip ] dip
] while ] while
>byte-vector >byte-vector