Optimize PySide::getMetaDataFromQObject function avoiding some str copies.

This commit is contained in:
Hugo Parente Lima 2011-10-26 16:23:28 -02:00
commit f55d088d44

View file

@ -38,6 +38,7 @@
#include <typeresolver.h> #include <typeresolver.h>
#include <bindingmanager.h> #include <bindingmanager.h>
#include <algorithm> #include <algorithm>
#include <cstring>
#include <cctype> #include <cctype>
#include <QStack> #include <QStack>
#include <QCoreApplication> #include <QCoreApplication>
@ -233,30 +234,34 @@ PyObject* getMetaDataFromQObject(QObject* cppSelf, PyObject* self, PyObject* nam
} }
//search on metaobject (avoid internal attributes started with '__') //search on metaobject (avoid internal attributes started with '__')
if (!attr && !QString(Shiboken::String::toCString(name)).startsWith("__")) { if (!attr) {
const QMetaObject* metaObject = cppSelf->metaObject(); const char* cname = Shiboken::String::toCString(name);
QByteArray cname(Shiboken::String::toCString(name)); uint cnameLen = qstrlen(cname);
cname += '('; if (std::strncmp("__", cname, 2)) {
//signal const QMetaObject* metaObject = cppSelf->metaObject();
QList<QMetaMethod> signalList; //signal
for(int i=0, i_max = metaObject->methodCount(); i < i_max; i++) { QList<QMetaMethod> signalList;
QMetaMethod method = metaObject->method(i); for(int i=0, i_max = metaObject->methodCount(); i < i_max; i++) {
if (QString(method.signature()).startsWith(cname)) { QMetaMethod method = metaObject->method(i);
if (method.methodType() == QMetaMethod::Signal) { const char* methSig = method.signature();
signalList.append(method); bool methMacth = !std::strncmp(cname, methSig, cnameLen) && methSig[cnameLen] == '(';
} else { if (methMacth) {
PySideMetaFunction* func = MetaFunction::newObject(cppSelf, i); if (method.methodType() == QMetaMethod::Signal) {
if (func) { signalList.append(method);
PyObject_SetAttr(self, name, (PyObject*)func); } else {
return (PyObject*)func; PySideMetaFunction* func = MetaFunction::newObject(cppSelf, i);
if (func) {
PyObject_SetAttr(self, name, (PyObject*)func);
return (PyObject*)func;
}
} }
} }
} }
} if (signalList.size() > 0) {
if (signalList.size() > 0) { PyObject* pySignal = reinterpret_cast<PyObject*>(Signal::newObjectFromMethod(self, signalList));
PyObject* pySignal = reinterpret_cast<PyObject*>(Signal::newObjectFromMethod(self, signalList)); PyObject_SetAttr(self, name, pySignal);
PyObject_SetAttr(self, name, pySignal); return pySignal;
return pySignal; }
} }
} }
return attr; return attr;