repos
/
smoke
/ annotate_shade
summary
|
shortlog
|
log
|
tree
|
commit
|
commitdiff
|
headdiff
|
annotate
|
headblob
|
headfilediff
|
filehistory
normal
|
plain
|
shade
|
zebra
Don't dispatch virtual methods for builtin classes (reduces overhead).
Annotate for file src/libsmoke/smokebinding.cpp
2010-01-10 tobias
1
#include "smokebinding.h"
2009-04-05 tobias
2
15:36:29 '
3
#include <QtGlobal>
2009-08-02 tobias
4
#include <QDebug>
2009-04-05 tobias
5
15:36:29 '
6
namespace cl_smoke
'
7
{
'
8
2010-02-18 tobias
9
/** @class NoDispatchBinding
19:57:00 '
10
* @brief The Smoke binding for classes we need no dispatching.
'
11
* This saves some overhead, since it does not call into Lisp.
'
12
* Idea stolen from CommonQt ;)
'
13
*
'
14
* Dispatches for non extended classes (not of class CXX:CLASS) are between
'
15
* 20% - 40% (for qt.examples:colliding-mice - qt.examples:class-browser). (18 February 2010)
2009-04-05 tobias
16
*/
15:36:29 '
17
2010-02-18 tobias
18
/** @typedef NoDispatchBinding::destructed
2009-04-05 tobias
19
* Callback when a Smoke object is destructed.
15:36:29 '
20
*
2009-08-02 tobias
21
* @param class_index Index of the object's class.
2009-06-22 tobias
22
* @param object pointer to the object
2009-04-05 tobias
23
*/
15:36:29 '
24
2010-02-18 tobias
25
/** Constructor.
19:57:00 '
26
* @param smoke the Smoke module
'
27
* @param destruct destruct callback
'
28
*/
'
29
NoDispatchBinding::NoDispatchBinding(Smoke *smoke, destructed destruct)
'
30
: SmokeBinding(smoke),
'
31
destruct(destruct)
'
32
{
'
33
Q_ASSERT(destruct);
'
34
}
'
35
'
36
/** Invoked when a Smoke object is destructed. */
'
37
void
'
38
NoDispatchBinding::deleted(Smoke::Index, void *object)
'
39
{
'
40
destruct(object);
'
41
}
'
42
'
43
/** Invoked when a Smoke method gets called. */
'
44
bool
'
45
NoDispatchBinding::callMethod(Smoke::Index method, void* object,
'
46
Smoke::Stack stack, bool abstract)
'
47
{
'
48
Q_ASSERT(!abstract);
'
49
return false;
'
50
}
'
51
'
52
/**
'
53
* @todo Returning a const char* would be better
'
54
*/
'
55
char*
'
56
NoDispatchBinding::className(Smoke::Index classId)
'
57
{
'
58
Q_ASSERT(classId >= 0 && classId <= smoke->numClasses);
'
59
return const_cast<char*>(smoke->classes[classId].className);
'
60
}
'
61
'
62
/** @function NoDispatchBinding::get_smoke()
'
63
* Gets the Smoke instance associated with the binding.
'
64
* @return a pointer to the Smoke instance
'
65
*/
'
66
'
67
/** @class Binding
'
68
* @brief The Smoke binding.
'
69
*/
2009-04-05 tobias
70
15:36:29 '
71
/** @typedef Binding::dispatch_method
'
72
* Callback when a Smoke method gets called.
'
73
*
'
74
* @param binding Smoke binding of @a object
'
75
* @param method index of the method
'
76
* @param object the object for which the method is called
'
77
* @param args the arguments to the method
'
78
* @param abstract @c true when the method is abstract and @c false otherwise
'
79
*
'
80
* @return @c true when the method call was handled and @c false
2009-06-22 tobias
81
* when the default method shall be invoked.
2009-04-05 tobias
82
*/
15:36:29 '
83
'
84
/** Constructor.
2010-02-19 tobias
85
* @param smoke the Smoke module
2009-04-05 tobias
86
* @param destruct destruct callback
15:36:29 '
87
* @param dispatch method dispatch callback
'
88
*/
2010-02-19 tobias
89
Binding::Binding(Smoke *smoke, destructed destruct,
21:10:24 '
90
dispatch_method dispatch)
2010-02-18 tobias
91
: NoDispatchBinding(smoke, destruct),
2009-04-05 tobias
92
dispatch(dispatch)
15:36:29 '
93
{
'
94
Q_ASSERT(dispatch);
'
95
}
'
96
'
97
2009-06-03 tobias
98
/** Invoked when a Smoke method gets called. */
2009-04-05 tobias
99
bool
15:36:29 '
100
Binding::callMethod(Smoke::Index method, void* object,
'
101
Smoke::Stack stack, bool abstract)
'
102
{
2010-02-19 tobias
103
int ret = dispatch(this, method, object, stack, abstract);
2009-06-03 tobias
104
Q_ASSERT( !abstract || ret );
21:55:26 '
105
'
106
return ret;
2009-04-05 tobias
107
}
15:36:29 '
108
'
109
} // namespace cl_smoke