]> gitweb.factorcode.org Git - factor.git/commitdiff
hashtables: cleanup duplicate code.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 7 Apr 2013 04:36:39 +0000 (21:36 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 7 Apr 2013 04:36:39 +0000 (21:36 -0700)
core/hashtables/hashtables.factor

index 420d525e59ff9a3005df23ffd57ee1a43e92a7fa..5327d122d7bfcefb9a78bb712c2b16ed96231e29 100644 (file)
@@ -155,22 +155,18 @@ M: hashtable set-at
     [ [ 1 fixnum+fast { array-capacity } declare ] dip length<< ]
     2bi ; inline
 
+: collect-pairs ( hash quot: ( key value -- elt ) -- seq )
+    [ [ array>> ] [ assoc-size <vector> ] bi ] dip swap [
+        [ push-unsafe ] curry compose each-pair
+    ] keep { } like ; inline
+
 PRIVATE>
 
-M: hashtable >alist
-    [ array>> ] [ assoc-size <vector> ] bi [
-        [ [ 2array ] dip push-unsafe ] curry each-pair
-    ] keep { } like ;
+M: hashtable >alist [ 2array ] collect-pairs ;
 
-M: hashtable keys
-    [ array>> ] [ assoc-size <vector> ] bi [
-        [ nip push-unsafe ] curry each-pair
-    ] keep { } like ;
+M: hashtable keys [ drop ] collect-pairs ;
 
-M: hashtable values
-    [ array>> ] [ assoc-size <vector> ] bi [
-        [ [ drop ] 2dip push-unsafe ] curry each-pair
-    ] keep { } like ;
+M: hashtable values [ nip ] collect-pairs ;
 
 M: hashtable clone
     (clone) [ clone ] change-array ; inline