diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-10-22 16:27:50 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-10-23 10:18:24 (GMT) |
commit | d610da0f40819213fd45bf77f6c2131769df693d (patch) | |
tree | 42c45c142cf57554a5600b1fdc87be5cb765a04b /src/script/api/qscriptvalue.cpp | |
parent | 7bfa219ebd050523ecd0d72ad7154e1ce3b83ae9 (diff) | |
download | Qt-d610da0f40819213fd45bf77f6c2131769df693d.zip Qt-d610da0f40819213fd45bf77f6c2131769df693d.tar.gz Qt-d610da0f40819213fd45bf77f6c2131769df693d.tar.bz2 |
Inline internal property lookup function
Also avoid looking up the object's own properties twice
(before we called getOwnPropertySlot() and then getPropertySlot()
on the same object).
Makes QScriptValue::property() ~20% faster when calling it on an "empty" object.
Reviewed-by: Olivier Goffart
Diffstat (limited to 'src/script/api/qscriptvalue.cpp')
-rw-r--r-- | src/script/api/qscriptvalue.cpp | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp index 21673d1..76b2636 100644 --- a/src/script/api/qscriptvalue.cpp +++ b/src/script/api/qscriptvalue.cpp @@ -276,41 +276,36 @@ qsreal ToInteger(qsreal n) } // namespace QScript -QScriptValue QScriptValuePrivate::property(const JSC::Identifier &id, int resolveMode) const +QScriptValue QScriptValuePrivate::propertyHelper(const JSC::Identifier &id, int resolveMode) const { - Q_ASSERT(isObject()); - JSC::ExecState *exec = engine->currentFrame; - JSC::JSObject *object = JSC::asObject(jscValue); - JSC::PropertySlot slot(const_cast<JSC::JSObject*>(object)); JSC::JSValue result; - if (const_cast<JSC::JSObject*>(object)->getOwnPropertySlot(exec, id, slot)) { - result = slot.getValue(exec, id); - } else { - if ((resolveMode & QScriptValue::ResolvePrototype) - && const_cast<JSC::JSObject*>(object)->getPropertySlot(exec, id, slot)) { + if (!(resolveMode & QScriptValue::ResolvePrototype)) { + // Look in the object's own properties + JSC::ExecState *exec = engine->currentFrame; + JSC::JSObject *object = JSC::asObject(jscValue); + JSC::PropertySlot slot(object); + if (object->getOwnPropertySlot(exec, id, slot)) result = slot.getValue(exec, id); - } else if (resolveMode & QScriptValue::ResolveScope) { - // ### check if it's a function object and look in the scope chain - QScriptValue scope = property(QString::fromLatin1("__qt_scope__"), QScriptValue::ResolveLocal); - if (scope.isObject()) - result = engine->scriptValueToJSCValue(QScriptValuePrivate::get(scope)->property(id, resolveMode)); - } + } + if (!result && (resolveMode & QScriptValue::ResolveScope)) { + // ### check if it's a function object and look in the scope chain + QScriptValue scope = property(QString::fromLatin1("__qt_scope__"), QScriptValue::ResolveLocal); + if (scope.isObject()) + result = engine->scriptValueToJSCValue(QScriptValuePrivate::get(scope)->property(id, resolveMode)); } return engine->scriptValueFromJSCValue(result); } -QScriptValue QScriptValuePrivate::property(quint32 index, int resolveMode) const +QScriptValue QScriptValuePrivate::propertyHelper(quint32 index, int resolveMode) const { - Q_ASSERT(isObject()); - JSC::ExecState *exec = engine->currentFrame; - JSC::JSObject *object = JSC::asObject(jscValue); - JSC::PropertySlot slot(const_cast<JSC::JSObject*>(object)); JSC::JSValue result; - if (const_cast<JSC::JSObject*>(object)->getOwnPropertySlot(exec, index, slot)) { - result = slot.getValue(exec, index); - } else if ((resolveMode & QScriptValue::ResolvePrototype) - && const_cast<JSC::JSObject*>(object)->getPropertySlot(exec, index, slot)) { - result = slot.getValue(exec, index); + if (!(resolveMode & QScriptValue::ResolvePrototype)) { + // Look in the object's own properties + JSC::ExecState *exec = engine->currentFrame; + JSC::JSObject *object = JSC::asObject(jscValue); + JSC::PropertySlot slot(object); + if (object->getOwnPropertySlot(exec, index, slot)) + result = slot.getValue(exec, index); } return engine->scriptValueFromJSCValue(result); } |