]> gitweb.factorcode.org Git - factor.git/commitdiff
checksums: simplify add-checksum-bytes.
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 18 Feb 2014 02:25:51 +0000 (18:25 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 18 Feb 2014 02:25:51 +0000 (18:25 -0800)
core/checksums/checksums.factor

index 96df574b6fb54cfacfc259110cd6e5d382a9d3ee..f08f8abe1391d2eba85cc6cb7567110ffc174df3 100644 (file)
@@ -7,7 +7,9 @@ IN: checksums
 MIXIN: checksum
 
 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
@@ -17,7 +19,7 @@ M: checksum-state clone
     call-next-method
     [ clone ] change-bytes ;
 
-GENERIC: initialize-checksum-state ( class -- checksum-state )
+GENERIC: initialize-checksum-state ( checksum -- checksum-state )
 
 GENERIC: checksum-block ( bytes checksum -- )
 
@@ -27,9 +29,9 @@ GENERIC: get-checksum ( checksum -- value )
     over bytes>> [ push-all ] keep
     [ dup length pick block-size>> >= ]
     [
-        over block-size>> cut-slice [ >byte-array ] dip [
-            over [ checksum-block ]
-            [ [ ] [ block-size>> ] bi [ + ] curry change-bytes-read drop ] bi
+        over block-size>> cut-slice [
+            >byte-array over checksum-block
+            [ block-size>> ] keep [ + ] change-bytes-read
         ] dip
     ] while
     >byte-vector