summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/scriptengine.cpp
diff options
context:
space:
mode:
authorArttu Tarkiainen <arttu.tarkiainen@qt.io>2022-10-24 17:16:04 +0300
committerArttu Tarkiainen <arttu.tarkiainen@qt.io>2022-11-07 13:00:17 +0000
commitd259157bfe473ccb2cff4bdf37aee2e539ccee49 (patch)
treec6aec5d7dd295a64329d267bb0a4013796c9ea9e /src/libs/installer/scriptengine.cpp
parent19c6d36d03ef2dc55fdd30761ba38968aa12356c (diff)
InstallerProxy: optimize querying components by name
For some API compatibility with QtScript, the QInstaller::ScriptEngine's implementation of newQObject(QObject *object) method adds findChild() and findChildren() functions as properties for the JS object wrapping the QObject, QInstaller::Component in this case. This results in two extra QJSEngine::evaluate() calls, adding some overhead. The Component class does not utilize the QObject's object tree & ownership feature in the C++ side, so the functions do not add extra value in this context. InstallerProxy::ComponentByName() creates the JavaScript object of the component with the aforementioned ScriptEngine::newQObject() implementation. We inject a snippet resulting in a call to InstallerProxy's componentByName() function for each component script. Measuring with callgrind, the time spent in the extra evaluations was around fifth of the whole evaluation cycle. Modify the function to to make the addition of the extra properties optional, and omit them when querying components by name from script. Task-number: QTIFW-2790 Change-Id: I58040809dcf69599e0fabd98def2dc9464aadf84 Reviewed-by: Katja Marttila <katja.marttila@qt.io>
Diffstat (limited to 'src/libs/installer/scriptengine.cpp')
-rw-r--r--src/libs/installer/scriptengine.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/libs/installer/scriptengine.cpp b/src/libs/installer/scriptengine.cpp
index 009215909..3b2e3ae1d 100644
--- a/src/libs/installer/scriptengine.cpp
+++ b/src/libs/installer/scriptengine.cpp
@@ -95,7 +95,7 @@ QJSValue InstallerProxy::components(const QString &regexp) const
QJSValue InstallerProxy::componentByName(const QString &componentName)
{
if (m_core)
- return m_engine->newQObject(m_core->componentByName(componentName));
+ return m_engine->newQObject(m_core->componentByName(componentName), false);
return QJSValue();
}
@@ -418,9 +418,9 @@ ScriptEngine::ScriptEngine(PackageManagerCore *core) :
/*!
Creates a JavaScript object that wraps the given QObject \a object.
- Signals and slots, properties and children of \a object are
- available as properties of the created QJSValue. In addition some helper methods and properties
- are added:
+ Signals and slots, properties and children of \a object are available as properties
+ of the created QJSValue. If \a qtScriptCompat is set to \c true (default), some helper
+ methods and properties from the legacy \c QtScript module are added:
\list
\li findChild(), findChildren() recursively search for child objects with the given
@@ -429,7 +429,7 @@ ScriptEngine::ScriptEngine(PackageManagerCore *core) :
names.
\endlist
*/
-QJSValue ScriptEngine::newQObject(QObject *object)
+QJSValue ScriptEngine::newQObject(QObject *object, bool qtScriptCompat)
{
QJSValue jsValue = m_engine.newQObject(object);
if (!jsValue.isQObject())
@@ -437,6 +437,9 @@ QJSValue ScriptEngine::newQObject(QObject *object)
QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership);
+ if (!qtScriptCompat) // skip adding the extra properties
+ return jsValue;
+
// add findChild(), findChildren() methods known from QtScript
QJSValue findChild = m_engine.evaluate(
QLatin1String("(function() { return gui.findChild(this, arguments[0]); })"));