On Sun, Dec 14, 2008 at 3:49 PM, Didier Verna <didier.verna@...> wrote:
> the standard requires that slot initforms be evaluated everytime they're
> needed to initialize a slot. In the case where such an initform is a
> constant known at compile-time, for instance:
> (defclass foo () ((slot :initform 1 :type fixnum)))
> I'm wondering if SBCL does anything "clever" in terms of optimization.
> For instance, when (safety 3), we could think of bypassing the
> type-checking except for the first time, stuff like that.
Something like that. For MAKE-INSTANCE calls with a constant class
argument we construct a specialized constructor function, where
type-checking slot-initialization from a constant initform is
expressed as something like:
(setf (svref slots location) (the slot-type initform))
where the compiler is smart enough to optimize the type-check (implied
by THE for SBCL in safe code) if the constant type matches.
Details both gory and glorious in src/pcl/ctor.lisp.