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,15 +234,18 @@ 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 char* cname = Shiboken::String::toCString(name);
uint cnameLen = qstrlen(cname);
if (std::strncmp("__", cname, 2)) {
const QMetaObject* metaObject = cppSelf->metaObject(); const QMetaObject* metaObject = cppSelf->metaObject();
QByteArray cname(Shiboken::String::toCString(name));
cname += '(';
//signal //signal
QList<QMetaMethod> signalList; QList<QMetaMethod> signalList;
for(int i=0, i_max = metaObject->methodCount(); i < i_max; i++) { for(int i=0, i_max = metaObject->methodCount(); i < i_max; i++) {
QMetaMethod method = metaObject->method(i); QMetaMethod method = metaObject->method(i);
if (QString(method.signature()).startsWith(cname)) { const char* methSig = method.signature();
bool methMacth = !std::strncmp(cname, methSig, cnameLen) && methSig[cnameLen] == '(';
if (methMacth) {
if (method.methodType() == QMetaMethod::Signal) { if (method.methodType() == QMetaMethod::Signal) {
signalList.append(method); signalList.append(method);
} else { } else {
@ -259,6 +263,7 @@ PyObject* getMetaDataFromQObject(QObject* cppSelf, PyObject* self, PyObject* nam
return pySignal; return pySignal;
} }
} }
}
return attr; return attr;
} }