aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/common
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2024-01-08 12:56:38 +0100
committerUlf Hermann <ulf.hermann@qt.io>2024-01-13 16:03:58 +0100
commitc225e23e00bc539daefa357f687fe4a1b51ade9f (patch)
tree0cbb680ae5171ab0c84effd88af02d5b7bb3369a /src/qml/common
parent21cf48781655e03c099e54f180f78e7435367386 (diff)
QtQml: Move ResolvedTypeReference into base CU
Change-Id: I25063457aad3a6d29a8c2a5b236f9a51b56a2f51 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/common')
-rw-r--r--src/qml/common/qv4compileddata.cpp55
-rw-r--r--src/qml/common/qv4compileddata_p.h30
2 files changed, 68 insertions, 17 deletions
diff --git a/src/qml/common/qv4compileddata.cpp b/src/qml/common/qv4compileddata.cpp
index 14315084bd..16ef43f678 100644
--- a/src/qml/common/qv4compileddata.cpp
+++ b/src/qml/common/qv4compileddata.cpp
@@ -3,9 +3,10 @@
#include "qv4compileddata_p.h"
+#include <private/qv4resolvedtypereference_p.h>
+
#include <QtQml/qqmlfile.h>
-#include <QtCore/qcryptographichash.h>
#include <QtCore/qdir.h>
#include <QtCore/qscopeguard.h>
#include <QtCore/qstandardpaths.h>
@@ -15,6 +16,48 @@ QT_BEGIN_NAMESPACE
namespace QV4 {
namespace CompiledData {
+/*!
+ \internal
+ This function creates a temporary key vector and sorts it to guarantuee a stable
+ hash. This is used to calculate a check-sum on dependent meta-objects.
+ */
+bool ResolvedTypeReferenceMap::addToHash(
+ QCryptographicHash *hash, QHash<quintptr, QByteArray> *checksums) const
+{
+ std::vector<int> keys (size());
+ int i = 0;
+ for (auto it = constBegin(), end = constEnd(); it != end; ++it) {
+ keys[i] = it.key();
+ ++i;
+ }
+ std::sort(keys.begin(), keys.end());
+ for (int key: keys) {
+ if (!this->operator[](key)->addToHash(hash, checksums))
+ return false;
+ }
+
+ return true;
+}
+
+CompilationUnit::~CompilationUnit()
+{
+ qDeleteAll(resolvedTypes);
+
+ if (data) {
+ if (data->qmlUnit() != qmlData)
+ free(const_cast<QmlUnit *>(qmlData));
+ qmlData = nullptr;
+
+ if (!(data->flags & QV4::CompiledData::Unit::StaticData))
+ free(const_cast<Unit *>(data));
+ }
+ data = nullptr;
+#if Q_BYTE_ORDER == Q_BIG_ENDIAN
+ delete [] constants;
+ constants = nullptr;
+#endif
+}
+
QString CompilationUnit::localCacheFilePath(const QUrl &url)
{
static const QByteArray envCachePath = qgetenv("QML_DISK_CACHE_PATH");
@@ -117,6 +160,16 @@ QStringList CompilationUnit::moduleRequests() const
return requests;
}
+ResolvedTypeReference *CompilationUnit::resolvedType(QMetaType type) const
+{
+ for (ResolvedTypeReference *ref : std::as_const(resolvedTypes)) {
+ if (ref->type().typeId() == type)
+ return ref;
+ }
+ return nullptr;
+
+}
+
} // namespace CompiledData
} // namespace QV4
diff --git a/src/qml/common/qv4compileddata_p.h b/src/qml/common/qv4compileddata_p.h
index d9268c8407..0adac2874c 100644
--- a/src/qml/common/qv4compileddata_p.h
+++ b/src/qml/common/qv4compileddata_p.h
@@ -16,6 +16,7 @@
#include <functional>
+#include <QtCore/qcryptographichash.h>
#include <QtCore/qhash.h>
#include <QtCore/qhashfunctions.h>
#include <QtCore/qlocale.h>
@@ -74,12 +75,19 @@ struct InternalClass;
struct Function;
class EvalISelFactory;
+class ResolvedTypeReference;
namespace CompiledData {
// index is per-object binding index
using BindingPropertyData = QVector<const QQmlPropertyData *>;
+// map from name index
+struct ResolvedTypeReferenceMap: public QHash<int, ResolvedTypeReference*>
+{
+ bool addToHash(QCryptographicHash *hash, QHash<quintptr, QByteArray> *checksums) const;
+};
+
struct String;
struct Function;
struct Lookup;
@@ -1473,6 +1481,8 @@ struct CompilationUnit final : public QQmlRefCounted<CompilationUnit>
// lookups by string (property name).
QVector<BindingPropertyData> bindingPropertyDataPerObject;
+ ResolvedTypeReferenceMap resolvedTypes;
+
public:
using CompiledObject = CompiledData::Object;
@@ -1489,22 +1499,7 @@ public:
this->aotCompiledFunctions = aotCompiledFunctions;
}
- ~CompilationUnit()
- {
- if (data) {
- if (data->qmlUnit() != qmlData)
- free(const_cast<QmlUnit *>(qmlData));
- qmlData = nullptr;
-
- if (!(data->flags & QV4::CompiledData::Unit::StaticData))
- free(const_cast<Unit *>(data));
- }
- data = nullptr;
-#if Q_BYTE_ORDER == Q_BIG_ENDIAN
- delete [] constants;
- constants = nullptr;
-#endif
- }
+ Q_QML_EXPORT ~CompilationUnit();
const Unit *unitData() const { return data; }
@@ -1620,6 +1615,9 @@ public:
return m_finalUrl;
}
+ ResolvedTypeReference *resolvedType(int id) const { return resolvedTypes.value(id); }
+ ResolvedTypeReference *resolvedType(QMetaType type) const;
+
private:
QString m_fileName; // initialized from data->sourceFileIndex
QString m_finalUrlString; // initialized from data->finalUrlIndex