Add declarations to gtype functions so that sbcl would allocate less
[cl-gtk2.git] / glib / gobject.type-designator.lisp
index d31af2e..8546386 100644 (file)
@@ -23,6 +23,7 @@
   (type g-type))
 
 (defun gtype-from-name (name)
+  (declare (optimize (safety 0) (speed 3)))
   (when (null name) (return-from gtype-from-name nil))
   (bt:with-lock-held (*gtype-lock*)
     (let ((type (gethash name *name-to-gtype*)))
@@ -45,6 +46,7 @@
         (return-from gtype-from-name type)))))
 
 (defun gtype-from-id (id)
+  (declare (optimize (safety 0) (speed 3)))
   (when (zerop id) (return-from gtype-from-id nil))
   (bt:with-lock-held (*gtype-lock*)
     (let ((type (gethash id *id-to-gtype*)))
             (gethash n *id-to-gtype*) gtype)
       n)))
 
-(defun gtype (thing)
+(defun %gtype (thing)
   (etypecase thing
     (null nil)
     (gtype thing)
     (string (gtype-from-name thing))
     (integer (gtype-from-id thing))))
 
+(defun gtype (thing)
+  (%gtype thing))
+
+(define-compiler-macro gtype (&whole whole thing)
+  (if (constantp thing)
+      `(load-time-value (%gtype ,thing))
+      whole))
+
 (define-foreign-type g-type-designator ()
   ((mangled-p :initarg :mangled-p
               :reader g-type-designator-mangled-p