blob: 6c687661f9502c7c42eb78067342b39f54b51661 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtQmlDom/private/qqmldomtop_p.h>
#include <QtQmlDom/private/qqmldomitem_p.h>
#include <QtTest/QtTest>
#include <QtCore/QLibraryInfo>
class tst_qmldomconstruction : public QObject
{
Q_OBJECT
private slots:
void domConstructionTime_data();
void domConstructionTime();
};
void tst_qmldomconstruction::domConstructionTime_data()
{
using namespace QQmlJS::Dom;
using namespace Qt::StringLiterals;
const auto baseDir = QLatin1String(SRCDIR) + QLatin1String("/data");
QTest::addColumn<QString>("fileName");
QTest::addColumn<DomCreationOptions>("withScope");
DomCreationOptions withScope = DomCreationOption::WithSemanticAnalysis;
DomCreationOptions noScope = DomCreationOption::None;
DomCreationOptions withScopeAndScriptExpressions;
withScopeAndScriptExpressions.setFlag(DomCreationOption::WithSemanticAnalysis);
withScopeAndScriptExpressions.setFlag(DomCreationOption::WithScriptExpressions);
QTest::addRow("tiger.qml") << baseDir + u"/longQmlFile.qml"_s << noScope;
QTest::addRow("tiger.qml-with-scope") << baseDir + u"/longQmlFile.qml"_s << withScope;
QTest::addRow("tiger.qml-with-scope-and-scriptexpressions")
<< baseDir + u"/longQmlFile.qml"_s << withScopeAndScriptExpressions;
QTest::addRow("deeplyNested.qml") << baseDir + u"/deeplyNested.qml"_s << noScope;
QTest::addRow("deeplyNested.qml-with-scope") << baseDir + u"/deeplyNested.qml"_s << withScope;
QTest::addRow("deeplyNested.qml-with-scope-and-scriptexpressions")
<< baseDir + u"/deeplyNested.qml"_s << withScopeAndScriptExpressions;
}
void tst_qmldomconstruction::domConstructionTime()
{
using namespace QQmlJS::Dom;
QFETCH(QString, fileName);
QFETCH(DomCreationOptions, withScope);
const QStringList importPaths = {
QLibraryInfo::path(QLibraryInfo::QmlImportsPath),
};
DomItem tFile;
QBENCHMARK {
auto envPtr = DomEnvironment::create(
importPaths,
QQmlJS::Dom::DomEnvironment::Option::SingleThreaded
| QQmlJS::Dom::DomEnvironment::Option::NoDependencies, withScope);
envPtr->loadFile(FileToLoad::fromFileSystem(envPtr, fileName),
[&tFile](Path, const DomItem &, const DomItem &newIt) {
tFile = newIt.fileObject();
});
envPtr->loadPendingDependencies();
}
}
QTEST_MAIN(tst_qmldomconstruction)
#include "tst_qmldomconstruction.moc"
|