]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences: faster last / set-last.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 18 Jul 2012 19:31:53 +0000 (12:31 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 18 Jul 2012 19:31:53 +0000 (12:31 -0700)
core/sequences/sequences.factor

index 04cec9531b78e8f109361b74ad420066f7226f6b..08a475001a7696646c465a506f9382a374bd7412 100644 (file)
@@ -688,9 +688,13 @@ PRIVATE>
 
 : append! ( seq1 seq2 -- seq1 ) over push-all ; inline
 
-: last ( seq -- elt ) [ length 1 - ] [ nth ] bi ;
+: last ( seq -- elt )
+    [ length 1 - ] keep
+    over 0 < [ bounds-error ] [ nth-unsafe ] if ; inline
 
-: set-last ( elt seq -- ) [ length 1 - ] keep set-nth ;
+: set-last ( elt seq -- )
+    [ length 1 - ] keep
+    over 0 < [ bounds-error ] [ set-nth-unsafe ] if ; inline
 
 : pop* ( seq -- ) [ length 1 - ] [ shorten ] bi ;