Skip to content

Commit

Permalink
1.0.27.27: micro-optimize COERCE *->vector and vector->list
Browse files Browse the repository at this point in the history
* sprinkle type declarations around to avoid checking for general SEQUENCEs;

* use >= in loop exit tests to avoid checks for overflow.
  • Loading branch information
Nathan Froyd committed Apr 23, 2009
1 parent 512be71 commit 6de5179
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/code/coerce.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@

(macrolet ((def (name result access src-type &optional typep)
`(defun ,name (object ,@(if typep '(type) ()))
(declare (type ,(ecase src-type
(:list 'list)
(:vector 'vector)
(:sequence 'sequence)) object))
(do* ((index 0 (1+ index))
(length (length (the ,(ecase src-type
(:list 'list)
(:vector 'vector)
(:sequence 'sequence))
object)))
(length (length object))
(result ,result)
(in-object object))
((= index length) result)
((>= index length) result)
(declare (fixnum length index))
(declare (type vector result))
(setf (,access result index)
,(ecase src-type
(:list '(pop in-object))
Expand All @@ -39,12 +40,13 @@
aref :sequence t))

(defun vector-to-list* (object)
(declare (type vector object))
(let ((result (list nil))
(length (length object)))
(declare (fixnum length))
(do ((index 0 (1+ index))
(splice result (cdr splice)))
((= index length) (cdr result))
((>= index length) (cdr result))
(declare (fixnum index))
(rplacd splice (list (aref object index))))))

Expand Down
2 changes: 1 addition & 1 deletion version.lisp-expr
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
;;; checkins which aren't released. (And occasionally for internal
;;; versions, especially for internal versions off the main CVS
;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
"1.0.27.26"
"1.0.27.27"

0 comments on commit 6de5179

Please sign in to comment.