Comment 1 for bug 663979

Revision history for this message
Kalyanov Dmitry (kalyanov-dmitry) wrote :

I've read that CMUCL and SBCL have trouble with type inference when assignment is involved.
Just declaring count to be of integer type removes compiler notes about optimization and uses fixnum arithmetics.

(defun foo1 ()
  (declare (optimize speed))
  (let ((count 0))
    (declare (type integer count))
    (dotimes (i 100)
      (when (zerop (setq count (mod (1+ count) 10)))
        (bar)))))

(defun foo2 ()
  (declare (optimize speed))
  (loop repeat 100
        for count of-type integer = 0 then (mod (1+ count) 10)
        when (zerop count) do (bar)))