summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Alpert <aalpert@blackberry.com>2013-03-26 23:20:30 (GMT)
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-27 18:11:02 (GMT)
commitb3828295fdbfb684591795ca23d846d3e6126c0b (patch)
treefebaa329064b9cb67666f87bcc8bff21d4d3fcf8
parent543486a41963f8d20d9771d2107cdd5a22894bdb (diff)
downloadQt-b3828295fdbfb684591795ca23d846d3e6126c0b.zip
Qt-b3828295fdbfb684591795ca23d846d3e6126c0b.tar.gz
Qt-b3828295fdbfb684591795ca23d846d3e6126c0b.tar.bz2
Backport some enum optimizations from Qt 5
(backport of 108b9bbe2ff2f5f31525408a08d248499d95a49f in qtquick1) Saving the int when we check the enum is valid allows us to make it a literal assignment instead of a binding, which is much faster on object creation. Change-Id: Ieb174289438a17574c4716df372b04d4dee6d0db Reviewed-by: Christopher Adams <chris.adams@jollamobile.com>
-rw-r--r--src/declarative/qml/qdeclarativecompiler.cpp44
1 files changed, 33 insertions, 11 deletions
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp
index 38f73f7..c46585b 100644
--- a/src/declarative/qml/qdeclarativecompiler.cpp
+++ b/src/declarative/qml/qdeclarativecompiler.cpp
@@ -326,10 +326,14 @@ void QDeclarativeCompiler::genLiteralAssignment(const QMetaProperty &prop,
instr.line = v->location.start.line;
if (prop.isEnumType()) {
int value;
- if (prop.isFlagType()) {
- value = prop.enumerator().keysToValue(string.toUtf8().constData());
- } else
- value = prop.enumerator().keyToValue(string.toUtf8().constData());
+ if (v->value.isNumber()) { //Number saved from earlier check - not valid in testLiteralAssignment
+ value = v->value.asNumber();
+ } else {
+ if (prop.isFlagType())
+ value = prop.enumerator().keysToValue(string.toUtf8().constData());
+ else
+ value = prop.enumerator().keyToValue(string.toUtf8().constData());
+ }
instr.type = QDeclarativeInstruction::StoreInteger;
instr.storeInteger.propertyIndex = prop.propertyIndex();
@@ -2201,6 +2205,12 @@ bool QDeclarativeCompiler::buildPropertyLiteralAssignment(QDeclarativeParser::Pr
return true;
}
+struct StaticQtMetaObject : public QObject
+{
+ static const QMetaObject *get()
+ { return &static_cast<StaticQtMetaObject*> (0)->staticQtMetaObject; }
+};
+
bool QDeclarativeCompiler::testQualifiedEnumAssignment(const QMetaProperty &prop,
QDeclarativeParser::Object *obj,
QDeclarativeParser::Value *v,
@@ -2233,20 +2243,32 @@ bool QDeclarativeCompiler::testQualifiedEnumAssignment(const QMetaProperty &prop
objTypeName = objType->qmlTypeName();
}
- if (!type || objTypeName != type->qmlTypeName())
+ if (!type && typeName != QLatin1String("Qt"))
return true;
QString enumValue = parts.at(1);
- int value;
- if (prop.isFlagType()) {
- value = prop.enumerator().keysToValue(enumValue.toUtf8().constData());
- } else
- value = prop.enumerator().keyToValue(enumValue.toUtf8().constData());
+ int value = -1;
+
+ if (type && objTypeName == type->qmlTypeName()) {
+ if (prop.isFlagType()) {
+ value = prop.enumerator().keysToValue(enumValue.toUtf8().constData());
+ } else {
+ value = prop.enumerator().keyToValue(enumValue.toUtf8().constData());
+ }
+ } else {
+ QByteArray enumName = enumValue.toUtf8();
+ //Special case for Qt object
+ const QMetaObject *metaObject = type ? type->metaObject() : StaticQtMetaObject::get();
+ for (int ii = metaObject->enumeratorCount() - 1; value == -1 && ii >= 0; --ii) {
+ QMetaEnum e = metaObject->enumerator(ii);
+ value = e.keyToValue(enumName.constData());
+ }
+ }
if (value == -1)
return true;
v->type = Value::Literal;
- v->value = QDeclarativeParser::Variant(enumValue);
+ v->value = QDeclarativeParser::Variant((double)value);
*isAssignment = true;
return true;