mirror of
https://github.com/quickshell-mirror/quickshell.git
synced 2026-10-27 02:54:36 +00:00
core: reuse global pragma parsing js engine during scanning
QJSEngine cleanup is not fast or clean and results in speed degradation over time if too many are destroyed.
This commit is contained in:
2 files changed
+14
-4
No files matched your search
+11
-4
@@ -145,10 +145,7 @@ bool QmlScanner::scanQmlFile(const QString& path, bool& singleton, bool& interna
|
||||
QString overrideText;
|
||||
bool isOverridden = false;
|
||||
|
||||
auto pragmaEngine = QJSEngine();
|
||||
pragmaEngine.globalObject().setPrototype(
|
||||
pragmaEngine.newQObject(new qs::scan::env::PreprocEnv())
|
||||
);
|
||||
auto& pragmaEngine = *QmlScanner::preprocEngine();
|
||||
|
||||
auto postError = [&, this](QString error) {
|
||||
this->scanErrors.append({.file = path, .message = std::move(error), .line = lineNum});
|
||||
@@ -370,3 +367,13 @@ QPair<QString, QString> QmlScanner::jsonToQml(const QJsonValue& value, int inden
|
||||
return qMakePair(QStringLiteral("var"), "null");
|
||||
}
|
||||
}
|
||||
|
||||
QJSEngine* QmlScanner::preprocEngine() {
|
||||
static auto* engine = [] {
|
||||
auto* engine = new QJSEngine();
|
||||
engine->globalObject().setPrototype(engine->newQObject(new qs::scan::env::PreprocEnv()));
|
||||
return engine;
|
||||
}();
|
||||
|
||||
return engine;
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qdir.h>
|
||||
#include <qhash.h>
|
||||
#include <qjsengine.h>
|
||||
#include <qloggingcategory.h>
|
||||
#include <qvector.h>
|
||||
|
||||
@@ -42,4 +43,6 @@ private:
|
||||
bool scanQmlFile(const QString& path, bool& singleton, bool& internal);
|
||||
bool scanQmlJson(const QString& path);
|
||||
[[nodiscard]] static QPair<QString, QString> jsonToQml(const QJsonValue& value, int indent = 0);
|
||||
|
||||
static QJSEngine* preprocEngine();
|
||||
};
|
||||
Reference in new issue
Block a user