aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitrii Akshintsev <dmitrii.akshintsev@qt.io>2024-01-05 16:21:18 +0100
committerDmitrii Akshintsev <dmitrii.akshintsev@qt.io>2024-01-22 22:40:47 +0100
commit0f5929163cebb2c9f8e28f459e160b152f4f6a01 (patch)
tree65c8d841dc0e1a886faf117e3faa971770669e39 /src
parentf6fc3cc66e8c669b051c6a5eb3fa46a4d202a579 (diff)
DOM refactoring. DomUniverse::parse refactoring. Extract getValue helper
Extracting helper function to be reusable later + encapsulating lock acquiring. Minor step towards improving readability of DomUniverse::parse Task-number: QTBUG-119550 Change-Id: I52ebf4d4aba03b581e8ae277a7f4675407d2d5a7 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qmldom/qqmldomtop.cpp55
-rw-r--r--src/qmldom/qqmldomtop_p.h2
2 files changed, 39 insertions, 18 deletions
diff --git a/src/qmldom/qqmldomtop.cpp b/src/qmldom/qqmldomtop.cpp
index f30e4f5af5..818f48138d 100644
--- a/src/qmldom/qqmldomtop.cpp
+++ b/src/qmldom/qqmldomtop.cpp
@@ -315,21 +315,6 @@ void DomUniverse::parse(const FileToLoad &file, DomType fType, LoadOptions loadO
DomItem univ = DomItem(shared_from_this());
QVector<ErrorMessage> errors;
- auto getValue = [fType, this, &canonicalPath]() -> std::shared_ptr<ExternalItemPairBase> {
- if (fType == DomType::QmlFile)
- return m_qmlFileWithPath.value(canonicalPath);
- else if (fType == DomType::QmltypesFile)
- return m_qmlFileWithPath.value(canonicalPath);
- else if (fType == DomType::QmldirFile)
- return m_qmlFileWithPath.value(canonicalPath);
- else if (fType == DomType::QmlDirectory)
- return m_qmlDirectoryWithPath.value(canonicalPath);
- else if (fType == DomType::JsFile)
- return m_jsFileWithPath.value(canonicalPath);
- else
- Q_ASSERT(false);
- return {};
- };
if (code.isEmpty()) {
QFile file(canonicalPath);
QFileInfo path(canonicalPath);
@@ -338,8 +323,14 @@ void DomUniverse::parse(const FileToLoad &file, DomType fType, LoadOptions loadO
skipParse = true; // nothing to parse from the non-existing path
}
{
+ // This check is for the purpose of verifying whether the Universe has "lastModified"
+ // version of the ExtItemPair->current
+ // Mutex is being helpful here to guarantee that there are no changes
+ // done on the Value and CurrentItem during the checks.
+ // This is to sync this piece, piece on the line 355 and updateEntry method,
+ // where the update of the timestamp or the data might happen
QMutexLocker l(mutex());
- auto value = getValue();
+ auto value = getPathValueOrNull(fType, canonicalPath);
if (!(loadOptions & LoadOption::ForceLoad) && value) {
// use value also when its path is non-existing
if (value && value->currentItem()
@@ -355,8 +346,13 @@ void DomUniverse::parse(const FileToLoad &file, DomType fType, LoadOptions loadO
}
}
if (!skipParse) {
+ // This section is here to check whether the value (if present) has the most
+ // up-to-date content of the ExtItemPair->current and if so upd the timestamp.
+ // Mutex is being helpful here to guarantee that there are no changes
+ // done on the Value and CurrentItem during the checks.
+ // This is to sync this piece and updateEntry method, where the upd might happen
QMutexLocker l(mutex());
- if (auto value = getValue()) {
+ if (auto value = getPathValueOrNull(fType, canonicalPath)) {
QString oldCode = value->currentItem()->code();
if (value && value->currentItem() && !oldCode.isNull() && oldCode == code) {
skipParse = true;
@@ -528,6 +524,31 @@ std::shared_ptr<JsFile> DomUniverse::parseJsFile(const QString &code, const File
return jsFile;
}
+/*!
+ \internal
+ Queries the corresponding path map attempting to get the value
+ *WARNING* Usage of this function should be protected by the read lock
+ */
+std::shared_ptr<ExternalItemPairBase> DomUniverse::getPathValueOrNull(DomType fType,
+ const QString &path)
+{
+ switch (fType) {
+ case DomType::QmlFile:
+ return m_qmlFileWithPath.value(path);
+ case DomType::QmltypesFile:
+ return m_qmltypesFileWithPath.value(path);
+ case DomType::QmldirFile:
+ return m_qmldirFileWithPath.value(path);
+ case DomType::QmlDirectory:
+ return m_qmlDirectoryWithPath.value(path);
+ case DomType::JsFile:
+ return m_jsFileWithPath.value(path);
+ default:
+ Q_ASSERT(false);
+ }
+ return nullptr;
+}
+
std::shared_ptr<OwningItem> LoadInfo::doCopy(const DomItem &self) const
{
auto res = std::make_shared<LoadInfo>(*this);
diff --git a/src/qmldom/qqmldomtop_p.h b/src/qmldom/qqmldomtop_p.h
index 9eeffb242b..fb51e93bb9 100644
--- a/src/qmldom/qqmldomtop_p.h
+++ b/src/qmldom/qqmldomtop_p.h
@@ -320,7 +320,7 @@ private:
const QDateTime &contentDate);
std::shared_ptr<JsFile> parseJsFile(const QString &code, const FileToLoad &file,
const QDateTime &contentDate);
-
+ std::shared_ptr<ExternalItemPairBase> getPathValueOrNull(DomType fType, const QString &path);
private:
QString m_name;
QMap<QString, std::shared_ptr<ExternalItemPair<GlobalScope>>> m_globalScopeWithName;