Don't dispatch virtual methods for builtin classes (reduces overhead).
src/smoke.lisp
Thu Feb 18 20:57:00 CET 2010 Tobias Rautenkranz <tobias@rautenkranz.ch>
* Don't dispatch virtual methods for builtin classes (reduces overhead).
--- old-smoke/src/smoke.lisp 2014-10-30 08:06:57.000000000 +0100
+++ new-smoke/src/smoke.lisp 2014-10-30 08:06:57.000000000 +0100
@@ -82,25 +82,31 @@
(defun set-binding (object)
"Sets the Smoke binding for OBJECT, that receives its callbacks."
(declare (optimize (speed 3)))
- (with-foreign-object (stack 'smoke-stack-item 2)
- (setf (foreign-slot-value (mem-aref stack 'smoke-stack-item 1)
- 'smoke-stack-item 'voidp)
- (smoke-module-binding (smoke (class-of object))))
- (foreign-funcall-pointer
- (foreign-slot-value (smoke-class-pointer (class-of object))
- 'smoke-class 'class-function)
- ()
- smoke-index 0 ;; set binding method index
- :pointer (pointer object)
- smoke-stack stack
- :void)))
+ (let ((class (class-of object)))
+ (with-foreign-object (stack 'smoke-stack-item 2)
+ (setf (foreign-slot-value (mem-aref stack 'smoke-stack-item 1)
+ 'smoke-stack-item 'voidp)
+ (if (typep class 'cxx:class)
+ (smoke-module-binding (smoke class))
+ (smoke-module-no-dispatch-binding (smoke class))))
+ (foreign-funcall-pointer
+ (foreign-slot-value (smoke-class-pointer class)
+ 'smoke-class 'class-function)
+ ()
+ smoke-index 0 ;; set binding method index
+ :pointer (pointer object)
+ smoke-stack stack
+ :void))))
(defun init (smoke module)
"Returns the a new Smoke binding for the Smoke module SMOKE."
(use-foreign-library libclsmoke)
- (let* ((binding (smoke-init smoke (callback destructed)
- (callback dispatch-method))))
+ (let ((no-dispatch-binding
+ (smoke-construct-binding smoke (callback destructed) (null-pointer)))
+ (binding (smoke-construct-binding smoke (callback destructed)
+ (callback dispatch-method))))
(setf (smoke-module-pointer module) smoke
+ (smoke-module-no-dispatch-binding module) no-dispatch-binding
(smoke-module-binding module) binding)
(init-smoke-module module)
(setf (gethash (pointer-address smoke) *smoke-modules*) module)