The optimization works safely but without boxing when possible. You need
(optimize (float 0))
to get the optimization. This
float
level affects whether INT32 operations are optimized. This declaration must be placed at the start of a function (not on an inner
let
or
locally
form).
In this example the
safety
level assures a second optimization in
fli:foreign-typed-aref
:
(defun incf-signed-byte-32 (ptr index)
(declare (optimize (safety 0) (float 0))
(type fixnum index))
(setf (fli:foreign-typed-aref 'sys:int32 ptr index)
(sys:int32-1+ (fli:foreign-typed-aref 'sys:int32
ptr index)))
;; return ptr, since otherwise the int32 would
;; need to be boxed to return it
ptr)