summaryrefslogtreecommitdiff
path: root/src/webchannel/qmetaobjectpublisher.cpp
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2013-12-28 15:43:09 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-08 15:04:34 +0100
commit2f7bef547e51ee6f2fe8f12bbe33f4978d6bd7f2 (patch)
treeb1699169a411ef7e013c97c8525745a9dd899b3a /src/webchannel/qmetaobjectpublisher.cpp
parent5354cb73e25afbdf55b78c29ca32c1b305aa7efe (diff)
downloadqtwebchannel-2f7bef547e51ee6f2fe8f12bbe33f4978d6bd7f2.tar.gz
Optimize: Use property-indices instead of names for notifications.
This reduces the traffic as the indices are usually much smaller than the property names. As such, the benchPropertyUpdates gets a speed boost of about 9% (or 10ms vs. 11ms). As we need to transmit the index during initialization that degrades its performance slightly by ca. 4% (13ms vs. 12.5ms). Considering that the initialization only takes place once whereas the property updates potentially often, this is a good tradeoff. Change-Id: If7df3e360f1528b7d7aa26c63ce851363ae9fd6a Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/webchannel/qmetaobjectpublisher.cpp')
-rw-r--r--src/webchannel/qmetaobjectpublisher.cpp36
1 files changed, 17 insertions, 19 deletions
diff --git a/src/webchannel/qmetaobjectpublisher.cpp b/src/webchannel/qmetaobjectpublisher.cpp
index 3621fca..27c7d70 100644
--- a/src/webchannel/qmetaobjectpublisher.cpp
+++ b/src/webchannel/qmetaobjectpublisher.cpp
@@ -140,8 +140,8 @@ void QMetaObjectPublisherPrivate::initializePropertyUpdates(const QObject *const
qWarning() << "Invalid property info encountered:" << propertyInfoVar;
continue;
}
- const QString &propertyName = propertyInfo.at(0).toString();
- const QJsonArray &signalData = propertyInfo.at(1).toArray();
+ const int propertyIndex = propertyInfo.at(0).toInt();
+ const QJsonArray &signalData = propertyInfo.at(2).toArray();
if (signalData.isEmpty()) {
// Property without NOTIFY signal
@@ -150,14 +150,14 @@ void QMetaObjectPublisherPrivate::initializePropertyUpdates(const QObject *const
const int signalIndex = signalData.at(1).toInt();
- QSet<QString> &connectedProperties = signalToPropertyMap[object][signalIndex];
+ QSet<int> &connectedProperties = signalToPropertyMap[object][signalIndex];
// Only connect for a property update once
if (connectedProperties.isEmpty()) {
signalHandler.connectTo(object, signalIndex);
}
- connectedProperties.insert(propertyName);
+ connectedProperties.insert(propertyIndex);
}
// also always connect to destroyed signal
@@ -184,17 +184,12 @@ void QMetaObjectPublisherPrivate::sendPendingPropertyUpdates()
QJsonObject sigs;
const SignalToArgumentsMap::const_iterator sigEnd = it.value().constEnd();
for (SignalToArgumentsMap::const_iterator sigIt = it.value().constBegin(); sigIt != sigEnd; ++sigIt) {
- // TODO: use property indices
- foreach (const QString &propertyName, objectsSignalToPropertyMap.value(sigIt.key())) {
- int propertyIndex = metaObject->indexOfProperty(qPrintable(propertyName));
- if (propertyIndex == -1) {
- qWarning("Unknown property %d encountered", propertyIndex);
- continue;
- }
+ // TODO: can we get rid of the int <-> string conversions here?
+ foreach (const int propertyIndex, objectsSignalToPropertyMap.value(sigIt.key())) {
const QMetaProperty &property = metaObject->property(propertyIndex);
- properties[QString::fromLatin1(property.name())] = QJsonValue::fromVariant(property.read(object));
+ Q_ASSERT(property.isValid());
+ properties[QString::number(propertyIndex)] = QJsonValue::fromVariant(property.read(object));
}
- // TODO: can we get rid of the int <-> string conversions here?
sigs[QString::number(sigIt.key())] = QJsonArray::fromVariantList(sigIt.value());
}
QJsonObject obj;
@@ -390,6 +385,7 @@ QJsonObject QMetaObjectPublisher::classInfoForObject(QObject *object) const
const QMetaProperty &prop = metaObject->property(i);
QJsonArray propertyInfo;
const QString &propertyName = QString::fromLatin1(prop.name());
+ propertyInfo.append(i);
propertyInfo.append(propertyName);
identifiers << propertyName;
QJsonArray signalInfo;
@@ -520,14 +516,16 @@ bool QMetaObjectPublisher::handleRequest(const QJsonObject &message)
d->signalHandler.disconnectFrom(object, payload.value(KEY_SIGNAL).toInt(-1));
return true;
} else if (type == TYPE_SET_PROPERTY) {
- // TODO: use property indices
- const QString &propertyName = payload.value(KEY_PROPERTY).toString();
- const int propertyIdx = object->metaObject()->indexOfProperty(qPrintable(propertyName));
- if (propertyIdx == -1) {
- qWarning() << "Cannot set unknown property" << propertyName << "of object" << objectName;
+ const int propertyIdx = payload.value(KEY_PROPERTY).toInt(-1);
+ QMetaProperty property = object->metaObject()->property(propertyIdx);
+ if (!property.isValid()) {
+ qWarning() << "Cannot set unknown property" << payload.value(KEY_PROPERTY) << "of object" << objectName;
+ return false;
+ } else if (!object->metaObject()->property(propertyIdx).write(object, payload.value(KEY_VALUE).toVariant())) {
+ qWarning() << "Could not write value " << payload.value(KEY_VALUE)
+ << "to property" << property.name() << "of object" << objectName;
return false;
}
- object->metaObject()->property(propertyIdx).write(object, payload.value(KEY_VALUE).toVariant());
return true;
}
}