]> gitweb.factorcode.org Git - factor.git/commitdiff
hash-sets: faster grow-hash by not calling members.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 21 Mar 2013 06:02:28 +0000 (23:02 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 21 Mar 2013 06:02:28 +0000 (23:02 -0700)
core/hash-sets/hash-sets.factor

index ef873126b0c33bfc91e2794e1e35c2af651034f0..a094c015b23ce2b4d40a10d132ccfd2b39879ab4 100644 (file)
@@ -71,12 +71,18 @@ TUPLE: hash-set
     [ count>> 3 fixnum*fast 1 fixnum+fast ]
     [ array>> length>> 1 fixnum-shift-fast ] bi fixnum> ; inline
 
+: each-member ( array quot: ( elt -- ) -- )
+    [
+        [ length ] keep
+        [ array-nth dup tombstone? [ drop ] ] curry
+    ] dip [ if ] curry compose each-integer ; inline
+
 : grow-hash ( hash -- )
     { hash-set } declare [
-        [ members { array } declare ]
+        [ array>> ]
         [ cardinality 1 + ]
         [ reset-hash ] tri
-    ] keep (rehash) ;
+    ] keep [ (adjoin) ] curry each-member ;
 
 : ?grow-hash ( hash -- )
     dup hash-large? [ grow-hash ] [ drop ] if ; inline
@@ -110,11 +116,8 @@ M: hash-set adjoin ( key hash-set -- )
     dup ?grow-hash (adjoin) ;
 
 M: hash-set members
-    [ array>> [ length ] keep ] [ cardinality <vector> ] bi [
-        [
-            [ array-nth ] dip over tombstone?
-            [ 2drop ] [ push-unsafe ] if
-        ] 2curry each-integer
+    [ array>> ] [ cardinality <vector> ] bi [
+        [ push-unsafe ] curry each-member
     ] keep { } like ;
 
 M: hash-set clone