]> gitweb.factorcode.org Git - factor.git/blobdiff - core/checksums/crc32/crc32.factor
endian: replaces io.binary and io.binary.fast.
[factor.git] / core / checksums / crc32 / crc32.factor
index f6f6870041649d54e588e64c2c9aa19c5b0ff881..d646a0440d31f07f35f33d756eb14454eba2c31a 100644 (file)
@@ -1,7 +1,6 @@
 ! Copyright (C) 2006 Doug Coleman
 ! See http://factorcode.org/license.txt for BSD license.
-USING: checksums io.binary kernel math sequences
-sequences.private ;
+USING: checksums kernel math sequences sequences.private ;
 IN: checksums.crc32
 
 CONSTANT: crc32-polynomial 0xedb88320
@@ -16,7 +15,7 @@ CONSTANT: crc32-table V{ }
 
 : (crc32) ( crc ch -- crc )
     dupd bitxor
-    mask-byte crc32-table nth-unsafe
+    0xff bitand crc32-table nth-unsafe
     swap -8 shift bitxor ; inline
 
 SINGLETON: crc32
@@ -26,8 +25,13 @@ INSTANCE: crc32 checksum
 : init-crc32 ( input checksum -- x y input )
     drop [ 0xffffffff dup ] dip ; inline
 
+<PRIVATE
+: 4>be ( n -- byte-array ) ! duplicated from io.binary, but in core
+    { -24 -16 -8 0 } [ shift 0xff bitand ] with B{ } map-as ;
+PRIVATE>
+
 : finish-crc32 ( x y -- bytes )
-    bitxor 4 >be ; inline
+    bitxor 4>be ; inline
 
 M: crc32 checksum-bytes
     init-crc32