From 73b14bae17d1bb84c89ca2a908f2cc105dcda015 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Fri, 23 Oct 2009 07:20:33 +0200 Subject: 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 --- src/script/api/qscriptengine.cpp | 50 +++++++++++++++------------------------- 1 file 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(ptr)); - break; + return QScriptValue(q, *reinterpret_cast(ptr)); case QMetaType::Int: - result = QScriptValue(q, *reinterpret_cast(ptr)); - break; + return QScriptValue(q, *reinterpret_cast(ptr)); case QMetaType::UInt: - result = QScriptValue(q, *reinterpret_cast(ptr)); - break; + return QScriptValue(q, *reinterpret_cast(ptr)); case QMetaType::LongLong: - result = QScriptValue(q, qsreal(*reinterpret_cast(ptr))); - break; + return QScriptValue(q, qsreal(*reinterpret_cast(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(ptr))); + return QScriptValue(q, qsreal((qlonglong)*reinterpret_cast(ptr))); #elif defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) - result = QScriptValue(q, qsreal((qlonglong)*reinterpret_cast(ptr))); + return QScriptValue(q, qsreal((qlonglong)*reinterpret_cast(ptr))); #else - result = QScriptValue(q, qsreal(*reinterpret_cast(ptr))); + return QScriptValue(q, qsreal(*reinterpret_cast(ptr))); #endif - break; case QMetaType::Double: - result = QScriptValue(q, qsreal(*reinterpret_cast(ptr))); - break; + return QScriptValue(q, qsreal(*reinterpret_cast(ptr))); case QMetaType::QString: - result = QScriptValue(q, *reinterpret_cast(ptr)); - break; + return QScriptValue(q, *reinterpret_cast(ptr)); case QMetaType::Float: - result = QScriptValue(q, *reinterpret_cast(ptr)); - break; + return QScriptValue(q, *reinterpret_cast(ptr)); case QMetaType::Short: - result = QScriptValue(q, *reinterpret_cast(ptr)); - break; + return QScriptValue(q, *reinterpret_cast(ptr)); case QMetaType::UShort: - result = QScriptValue(q, *reinterpret_cast(ptr)); - break; + return QScriptValue(q, *reinterpret_cast(ptr)); case QMetaType::Char: - result = QScriptValue(q, *reinterpret_cast(ptr)); - break; + return QScriptValue(q, *reinterpret_cast(ptr)); case QMetaType::UChar: - result = QScriptValue(q, *reinterpret_cast(ptr)); - break; + return QScriptValue(q, *reinterpret_cast(ptr)); case QMetaType::QChar: - result = QScriptValue(q, (*reinterpret_cast(ptr)).unicode()); - break; + return QScriptValue(q, (*reinterpret_cast(ptr)).unicode()); case QMetaType::QStringList: result = arrayFromStringList(*reinterpret_cast(ptr)); break; @@ -2596,7 +2582,7 @@ QScriptValue QScriptEnginePrivate::create(int type, const void *ptr) if (type == qMetaTypeId()) { result = *reinterpret_cast(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(ptr)); if (typeName.endsWith('*') && !*reinterpret_cast(ptr)) - result = QScriptValue(q, QScriptValue::NullValue); + return QScriptValue(q, QScriptValue::NullValue); else result = q->newVariant(QVariant(type, ptr)); } -- cgit v0.12