From a50b6ef977ca5d412e78e1105d81aa9bd3e18bf2 Mon Sep 17 00:00:00 2001 From: Douglas Katzman Date: Sat, 19 Mar 2016 12:48:59 -0400 Subject: [PATCH] Shorten DOTIMES expander, remove obsolete comments --- src/code/defboot.lisp | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/code/defboot.lisp b/src/code/defboot.lisp index 7f9980369..2b223291b 100644 --- a/src/code/defboot.lisp +++ b/src/code/defboot.lisp @@ -360,27 +360,15 @@ evaluated as a PROGN." allowing RETURN to be used as an alternate exit mechanism." (frob-do-body varlist endlist body 'let* 'setq 'do* nil))) -;;; DOTIMES and DOLIST could be defined more concisely using -;;; destructuring macro lambda lists or DESTRUCTURING-BIND, but then -;;; it'd be tricky to use them before those things were defined. -;;; They're used enough times before destructuring mechanisms are -;;; defined that it looks as though it's worth just implementing them -;;; ASAP, at the cost of being unable to use the standard -;;; destructuring mechanisms. (sb!xc:defmacro dotimes ((var count &optional (result nil)) &body body) - (cond ((integerp count) - `(do ((,var 0 (1+ ,var))) - ((>= ,var ,count) ,result) - (declare (type unsigned-byte ,var)) - ,@body)) - (t - (let ((c (gensym "COUNT"))) - `(do ((,var 0 (1+ ,var)) - (,c ,count)) - ((>= ,var ,c) ,result) - (declare (type unsigned-byte ,var) - (type integer ,c)) - ,@body))))) + ;; A nice optimization would be that if VAR is never referenced, + ;; it's slightly more efficient to count backwards, but that's tricky. + (let ((c (if (integerp count) count (sb!xc:gensym)))) + `(do ((,var 0 (1+ ,var)) + ,@(if (symbolp c) `((,c (the integer ,count))))) + ((>= ,var ,c) ,result) + (declare (type unsigned-byte ,var)) + ,@body))) (sb!xc:defmacro dolist ((var list &optional (result nil)) &body body &environment env) ;; We repeatedly bind the var instead of setting it so that we never -- 2.11.4.GIT