Don't dispatch virtual methods for builtin classes (reduces overhead).
src/libsmoke/smokebinding.cpp
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/libsmoke/smokebinding.cpp 2014-10-30 08:06:53.000000000 +0100
+++ new-smoke/src/libsmoke/smokebinding.cpp 2014-10-30 08:06:53.000000000 +0100
@@ -6,18 +6,67 @@
namespace cl_smoke
{
-/** @class Binding
- * @brief The Smoke binding.
+/** @class NoDispatchBinding
+ * @brief The Smoke binding for classes we need no dispatching.
+ * This saves some overhead, since it does not call into Lisp.
+ * Idea stolen from CommonQt ;)
+ *
+ * Dispatches for non extended classes (not of class CXX:CLASS) are between
+ * 20% - 40% (for qt.examples:colliding-mice - qt.examples:class-browser). (18 February 2010)
*/
-
-/** @typedef Binding::destructed
+/** @typedef NoDispatchBinding::destructed
* Callback when a Smoke object is destructed.
*
* @param class_index Index of the object's class.
* @param object pointer to the object
*/
+/** Constructor.
+ * @param smoke the Smoke module
+ * @param destruct destruct callback
+ */
+NoDispatchBinding::NoDispatchBinding(Smoke *smoke, destructed destruct)
+ : SmokeBinding(smoke),
+ destruct(destruct)
+{
+ Q_ASSERT(destruct);
+}
+
+/** Invoked when a Smoke object is destructed. */
+void
+NoDispatchBinding::deleted(Smoke::Index, void *object)
+{
+ destruct(object);
+}
+
+/** Invoked when a Smoke method gets called. */
+bool
+NoDispatchBinding::callMethod(Smoke::Index method, void* object,
+ Smoke::Stack stack, bool abstract)
+{
+ Q_ASSERT(!abstract);
+ return false;
+}
+
+/**
+ * @todo Returning a const char* would be better
+ */
+char*
+NoDispatchBinding::className(Smoke::Index classId)
+{
+ Q_ASSERT(classId >= 0 && classId <= smoke->numClasses);
+ return const_cast<char*>(smoke->classes[classId].className);
+}
+
+/** @function NoDispatchBinding::get_smoke()
+ * Gets the Smoke instance associated with the binding.
+ * @return a pointer to the Smoke instance
+ */
+
+/** @class Binding
+ * @brief The Smoke binding.
+ */
/** @typedef Binding::dispatch_method
* Callback when a Smoke method gets called.
@@ -39,21 +88,12 @@
*/
Binding::Binding(Smoke *smoke, destructed destruct,
dispatch_method dispatch)
- : SmokeBinding(smoke),
- destruct(destruct),
+ : NoDispatchBinding(smoke, destruct),
dispatch(dispatch)
{
- Q_ASSERT(smoke);
- Q_ASSERT(destruct);
Q_ASSERT(dispatch);
}
-/** Invoked when a Smoke object is destructed. */
-void
-Binding::deleted(Smoke::Index, void *object)
-{
- destruct(object);
-}
/** Invoked when a Smoke method gets called. */
bool
@@ -66,22 +106,4 @@
return ret;
}
-/**
- * @todo Returning a const char* would be better
- */
-char*
-Binding::className(Smoke::Index classId)
-{
- return const_cast<char*>(smoke->classes[classId].className);
-}
-
-/** Gets the Smoke instance associated with the binding.
- * @return a pointer to the Smoke instance
- */
-Smoke*
-Binding::get_smoke() const
-{
- return smoke;
-}
-
} // namespace cl_smoke