summaryrefslogtreecommitdiffstats
path: root/src/script/api
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-10-23 05:20:33 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-10-23 10:18:25 (GMT)
commit73b14bae17d1bb84c89ca2a908f2cc105dcda015 (patch)
treef22f7edea1412384a2839c55b6a7d05f358dc954 /src/script/api
parentfb0af528ed52a90d422b95f6976e21fd670f40b0 (diff)
downloadQt-73b14bae17d1bb84c89ca2a908f2cc105dcda015.zip
Qt-73b14bae17d1bb84c89ca2a908f2cc105dcda015.tar.gz
Qt-73b14bae17d1bb84c89ca2a908f2cc105dcda015.tar.bz2
Speed up QScriptValue creation by avoiding operator= to be called
For non-object values, just return the value immediately; there is no way that the later check (result.isObject()) will be true anyway. This makes qScriptValueFromValue() ~50% faster. Reviewed-by: Olivier Goffart
Diffstat (limited to 'src/script/api')
-rw-r--r--src/script/api/qscriptengine.cpp50
1 files changed, 18 insertions, 32 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp
index 654eea1..bffca16 100644
--- a/src/script/api/qscriptengine.cpp
+++ b/src/script/api/qscriptengine.cpp
@@ -2518,54 +2518,40 @@ QScriptValue QScriptEnginePrivate::create(int type, const void *ptr)
// check if it's one of the types we know
switch (QMetaType::Type(type)) {
case QMetaType::Void:
- result = QScriptValue(q, QScriptValue::UndefinedValue);
- break;
+ return QScriptValue(q, QScriptValue::UndefinedValue);
case QMetaType::Bool:
- result = QScriptValue(q, *reinterpret_cast<const bool*>(ptr));
- break;
+ return QScriptValue(q, *reinterpret_cast<const bool*>(ptr));
case QMetaType::Int:
- result = QScriptValue(q, *reinterpret_cast<const int*>(ptr));
- break;
+ return QScriptValue(q, *reinterpret_cast<const int*>(ptr));
case QMetaType::UInt:
- result = QScriptValue(q, *reinterpret_cast<const uint*>(ptr));
- break;
+ return QScriptValue(q, *reinterpret_cast<const uint*>(ptr));
case QMetaType::LongLong:
- result = QScriptValue(q, qsreal(*reinterpret_cast<const qlonglong*>(ptr)));
- break;
+ return QScriptValue(q, qsreal(*reinterpret_cast<const qlonglong*>(ptr)));
case QMetaType::ULongLong:
#if defined(Q_OS_WIN) && defined(_MSC_FULL_VER) && _MSC_FULL_VER <= 12008804
#pragma message("** NOTE: You need the Visual Studio Processor Pack to compile support for 64bit unsigned integers.")
- result = QScriptValue(q, qsreal((qlonglong)*reinterpret_cast<const qulonglong*>(ptr)));
+ return QScriptValue(q, qsreal((qlonglong)*reinterpret_cast<const qulonglong*>(ptr)));
#elif defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET)
- result = QScriptValue(q, qsreal((qlonglong)*reinterpret_cast<const qulonglong*>(ptr)));
+ return QScriptValue(q, qsreal((qlonglong)*reinterpret_cast<const qulonglong*>(ptr)));
#else
- result = QScriptValue(q, qsreal(*reinterpret_cast<const qulonglong*>(ptr)));
+ return QScriptValue(q, qsreal(*reinterpret_cast<const qulonglong*>(ptr)));
#endif
- break;
case QMetaType::Double:
- result = QScriptValue(q, qsreal(*reinterpret_cast<const double*>(ptr)));
- break;
+ return QScriptValue(q, qsreal(*reinterpret_cast<const double*>(ptr)));
case QMetaType::QString:
- result = QScriptValue(q, *reinterpret_cast<const QString*>(ptr));
- break;
+ return QScriptValue(q, *reinterpret_cast<const QString*>(ptr));
case QMetaType::Float:
- result = QScriptValue(q, *reinterpret_cast<const float*>(ptr));
- break;
+ return QScriptValue(q, *reinterpret_cast<const float*>(ptr));
case QMetaType::Short:
- result = QScriptValue(q, *reinterpret_cast<const short*>(ptr));
- break;
+ return QScriptValue(q, *reinterpret_cast<const short*>(ptr));
case QMetaType::UShort:
- result = QScriptValue(q, *reinterpret_cast<const unsigned short*>(ptr));
- break;
+ return QScriptValue(q, *reinterpret_cast<const unsigned short*>(ptr));
case QMetaType::Char:
- result = QScriptValue(q, *reinterpret_cast<const char*>(ptr));
- break;
+ return QScriptValue(q, *reinterpret_cast<const char*>(ptr));
case QMetaType::UChar:
- result = QScriptValue(q, *reinterpret_cast<const unsigned char*>(ptr));
- break;
+ return QScriptValue(q, *reinterpret_cast<const unsigned char*>(ptr));
case QMetaType::QChar:
- result = QScriptValue(q, (*reinterpret_cast<const QChar*>(ptr)).unicode());
- break;
+ return QScriptValue(q, (*reinterpret_cast<const QChar*>(ptr)).unicode());
case QMetaType::QStringList:
result = arrayFromStringList(*reinterpret_cast<const QStringList *>(ptr));
break;
@@ -2596,7 +2582,7 @@ QScriptValue QScriptEnginePrivate::create(int type, const void *ptr)
if (type == qMetaTypeId<QScriptValue>()) {
result = *reinterpret_cast<const QScriptValue*>(ptr);
if (!result.isValid())
- result = QScriptValue(q, QScriptValue::UndefinedValue);
+ return QScriptValue(q, QScriptValue::UndefinedValue);
}
#ifndef QT_NO_QOBJECT
@@ -2616,7 +2602,7 @@ QScriptValue QScriptEnginePrivate::create(int type, const void *ptr)
if (typeName == "QVariant")
result = scriptValueFromVariant(*reinterpret_cast<const QVariant*>(ptr));
if (typeName.endsWith('*') && !*reinterpret_cast<void* const *>(ptr))
- result = QScriptValue(q, QScriptValue::NullValue);
+ return QScriptValue(q, QScriptValue::NullValue);
else
result = q->newVariant(QVariant(type, ptr));
}