]> gitweb.factorcode.org Git - factor.git/commitdiff
hashtables: slightly faster grow logic.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 8 Mar 2013 04:51:46 +0000 (20:51 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 8 Mar 2013 04:51:46 +0000 (20:51 -0800)
core/hashtables/hashtables.factor

index 57dae0171f42ba584fb6e8c29f81a6501d4b6557..d2c5765df8a63bd9b7f45359873b96dbf371b6af 100644 (file)
@@ -88,16 +88,18 @@ TUPLE: hashtable
     1 fixnum+fast set-slot ; inline
 
 : (rehash) ( hash alist -- )
-    swap [ swapd set-at ] curry assoc-each ; inline
+    swap [ swapd dupd new-key@ set-nth-pair ] curry assoc-each ; inline
 
 : hash-large? ( hash -- ? )
     [ count>> 3 fixnum*fast 1 fixnum+fast ]
     [ array>> length>> ] bi fixnum> ; inline
 
 : grow-hash ( hash -- )
-    [ [ >alist ] [ assoc-size 1 + ] bi ] keep
-    [ reset-hash ] keep
-    swap (rehash) ;
+    { hashtable } declare [
+        [ >alist { array } declare ]
+        [ assoc-size 1 + ]
+        [ reset-hash ] tri
+    ] keep swap (rehash) ;
 
 : ?grow-hash ( hash -- )
     dup hash-large? [ grow-hash ] [ drop ] if ; inline