summaryrefslogtreecommitdiff
path: root/src/corelib/kernel/qmetaobject.cpp
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-08-17 10:17:27 +0200
committerOlivier Goffart <ogoffart@trolltech.com>2009-08-19 17:50:56 +0200
commit919b723088b8617b202b92d80b8d0983e4fd9500 (patch)
tree022472bc157e4f4e888929fe29f5b11ee8fef371 /src/corelib/kernel/qmetaobject.cpp
parent555fafe46e26b352e9d8ab5586910591761ab5ad (diff)
downloadqt4-tools-919b723088b8617b202b92d80b8d0983e4fd9500.tar.gz
Improve memory usage of the connectionlists inside QObject
... by not allocating space for slots in the vector. Before, the vector uses the signal index as index. The problem is that the slots and signal are mixed in the same index space. We solve the problem by having a different index space for the signal in the connectionlists vector. All we need to do is to add the information about the number of signals in the moc. Also, we are not connecting to cloned signal but only to the orginial ones. For example, destroyed(QObject * = 0) would generate two signal, we now only connect to the first one. This also improve a little bit the performence while activating signals since it removed one call to indexOfMethod. Reviewed-by: Brad
Diffstat (limited to 'src/corelib/kernel/qmetaobject.cpp')
-rw-r--r--src/corelib/kernel/qmetaobject.cpp102
1 files changed, 39 insertions, 63 deletions
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp
index 522f0dc09d..847938f434 100644
--- a/src/corelib/kernel/qmetaobject.cpp
+++ b/src/corelib/kernel/qmetaobject.cpp
@@ -140,63 +140,6 @@ QT_BEGIN_NAMESPACE
\value Public
*/
-// do not touch without touching the moc as well
-enum PropertyFlags {
- Invalid = 0x00000000,
- Readable = 0x00000001,
- Writable = 0x00000002,
- Resettable = 0x00000004,
- EnumOrFlag = 0x00000008,
- StdCppSet = 0x00000100,
-// Override = 0x00000200,
- Constant = 0x00000400,
- Final = 0x00000800,
- Designable = 0x00001000,
- ResolveDesignable = 0x00002000,
- Scriptable = 0x00004000,
- ResolveScriptable = 0x00008000,
- Stored = 0x00010000,
- ResolveStored = 0x00020000,
- Editable = 0x00040000,
- ResolveEditable = 0x00080000,
- User = 0x00100000,
- ResolveUser = 0x00200000,
- Notify = 0x00400000
-};
-
-enum MethodFlags {
- AccessPrivate = 0x00,
- AccessProtected = 0x01,
- AccessPublic = 0x02,
- AccessMask = 0x03, //mask
-
- MethodMethod = 0x00,
- MethodSignal = 0x04,
- MethodSlot = 0x08,
- MethodConstructor = 0x0c,
- MethodTypeMask = 0x0c,
-
- MethodCompatibility = 0x10,
- MethodCloned = 0x20,
- MethodScriptable = 0x40
-};
-
-enum MetaObjectFlags {
- DynamicMetaObject = 0x01
-};
-
-struct QMetaObjectPrivate
-{
- int revision;
- int className;
- int classInfoCount, classInfoData;
- int methodCount, methodData;
- int propertyCount, propertyData;
- int enumeratorCount, enumeratorData;
- int constructorCount, constructorData;
- int flags;
-};
-
static inline const QMetaObjectPrivate *priv(const uint* data)
{ return reinterpret_cast<const QMetaObjectPrivate*>(data); }
@@ -599,29 +542,46 @@ int QMetaObject::indexOfMethod(const char *method) const
*/
int QMetaObject::indexOfSignal(const char *signal) const
{
- int i = -1;
const QMetaObject *m = this;
- while (m && i < 0) {
+ int i = QMetaObjectPrivate::indexOfSignalRelative(&m, signal);
+ if (i >= 0)
+ i += m->methodOffset();
+ return i;
+}
+
+/*! \internal
+ Same as QMetaObject::indexOfSignal, but the result is the local offset to the base object.
+
+ \a baseObject will be adjusted to the enclosing QMetaObject, or 0 if the signal is not found
+*/
+int QMetaObjectPrivate::indexOfSignalRelative(const QMetaObject **baseObject, const char *signal)
+{
+ int i = -1;
+ while (*baseObject) {
+ const QMetaObject *const m = *baseObject;
for (i = priv(m->d.data)->methodCount-1; i >= 0; --i)
if ((m->d.data[priv(m->d.data)->methodData + 5*i + 4] & MethodTypeMask) == MethodSignal
&& strcmp(signal, m->d.stringdata
- + m->d.data[priv(m->d.data)->methodData + 5*i]) == 0) {
- i += m->methodOffset();
+ + m->d.data[priv(m->d.data)->methodData + 5*i]) == 0) {
break;
}
- m = m->d.superdata;
+ if (i >= 0)
+ break;
+ *baseObject = m->d.superdata;
}
#ifndef QT_NO_DEBUG
+ const QMetaObject *m = *baseObject;
if (i >= 0 && m && m->d.superdata) {
int conflict = m->d.superdata->indexOfMethod(signal);
if (conflict >= 0)
qWarning("QMetaObject::indexOfSignal:%s: Conflict with %s::%s",
- m->d.stringdata, m->d.superdata->d.stringdata, signal);
+ m->d.stringdata, m->d.superdata->d.stringdata, signal);
}
#endif
return i;
}
+
/*!
Finds \a slot and returns its index; otherwise returns -1.
@@ -2669,4 +2629,20 @@ const char* QMetaClassInfo::value() const
and \a data.
*/
+/*! \internal
+ If the local_method_index is a cloned method, return the index of the original.
+
+ Example: if the index of "destroyed()" is passed, the index of "destroyed(QObject*)" is returned
+ */
+int QMetaObjectPrivate::originalClone(const QMetaObject *mobj, int local_method_index)
+{
+ int handle = get(mobj)->methodData + 5 * local_method_index;
+ while (mobj->d.data[handle + 4] & MethodCloned) {
+ Q_ASSERT(local_method_index > 0);
+ handle -= 5;
+ local_method_index--;
+ }
+ return local_method_index;
+}
+
QT_END_NAMESPACE