]> gitweb.factorcode.org Git - factor.git/commitdiff
bit-arrays: fix resize method regression after recent equal? method optimization
authorSlava Pestov <slava@shill.local>
Wed, 29 Jul 2009 11:47:50 +0000 (06:47 -0500)
committerSlava Pestov <slava@shill.local>
Wed, 29 Jul 2009 11:47:50 +0000 (06:47 -0500)
basis/bit-arrays/bit-arrays.factor

index 42655aceb8e4c55ba8290b7cbe0f1ad5cbf63dc8..cdec87b61dc1f2f4a31689ea9e74fce89e560266 100644 (file)
@@ -27,6 +27,18 @@ TUPLE: bit-array
     [ [ length bits>cells ] keep ] dip swap underlying>>
     '[ 2 shift [ _ _ ] dip set-alien-unsigned-4 ] each ; inline
 
+: clean-up ( bit-array -- )
+    ! Zero bits after the end.
+    dup underlying>> empty? [ drop ] [
+        [
+            [ underlying>> length 8 * ] [ length ] bi -
+            8 swap - -1 swap shift bitnot
+        ]
+        [ underlying>> last bitand ]
+        [ underlying>> set-last ]
+        tri
+    ] if ; inline
+
 PRIVATE>
 
 : <bit-array> ( n -- bit-array )
@@ -68,7 +80,8 @@ M: bit-array resize
         [ bits>bytes ] [ underlying>> ] bi*
         resize-byte-array
     ] 2bi
-    bit-array boa ;
+    bit-array boa
+    dup clean-up ;
 
 M: bit-array byte-length length 7 + -3 shift ;