]> gitweb.factorcode.org Git - factor.git/commitdiff
sorting: speed up sort-keys and sort-values by doing less bounds checking.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 21 Mar 2013 00:06:51 +0000 (17:06 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 21 Mar 2013 00:06:51 +0000 (17:06 -0700)
core/sorting/sorting.factor

index 29bcafae20653b29b494eeb9d9f4b3e5e9c01da5..37407214f7a59e5d19740cb17ffa08fd9c93d17f 100644 (file)
@@ -153,16 +153,26 @@ PRIVATE>
 : inv-sort-with ( seq quot: ( elt -- key ) -- sortedseq )
     [ compare invert-comparison ] curry sort ; inline
 
+<PRIVATE
+
+: check-bounds ( alist n -- alist )
+    [ swap 2dup bounds-check? [ 2drop ] [ bounds-error ] if ]
+    curry dupd each ;
+
+PRIVATE>
+
 GENERIC: sort-keys ( obj -- sortedseq )
 
 M: object sort-keys >alist sort-keys ;
 
-M: sequence sort-keys [ first ] sort-with ;
+M: sequence sort-keys
+    0 check-bounds [ first-unsafe ] sort-with ;
 
 GENERIC: sort-values ( obj -- sortedseq )
 
 M: object sort-values >alist sort-values ;
 
-M: sequence sort-values [ second ] sort-with ;
+M: sequence sort-values
+    1 check-bounds [ second-unsafe ] sort-with ;
 
 : sort-pair ( a b -- c d ) 2dup after? [ swap ] when ;