From ef96d232e5355bf3d855f74c48c8d41f8c9bb89b Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Fri, 15 Mar 2024 14:11:20 +0100 Subject: [PATCH] QmlDesigner: Enable removal of trace points The value function could stop the optimizer to remove the trace point. The convert to string function is only called if there is a enabled trace point. Change-Id: I6ead32638438438602ac2116ffd353c6ed70b32d Reviewed-by: Qt CI Patch Build Bot Reviewed-by: Tim Jenssen --- .../projectstorage/projectstorage.h | 21 +-- .../projectstorage/projectstorageinfotypes.h | 11 ++ .../projectstorage/projectstoragetypes.h | 136 ++++++++++-------- 3 files changed, 97 insertions(+), 71 deletions(-) diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h index 344afae756f..b469dccda2d 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h @@ -1619,6 +1619,7 @@ private: Prototypes &relinkablePrototypes, Prototypes &relinkableExtensions) { + using NanotraceHR::keyValue; NanotraceHR::Tracer tracer{"synchronize exported types"_t, projectStorageCategory()}; std::sort(exportedTypes.begin(), exportedTypes.end(), [](auto &&first, auto &&second) { @@ -1662,7 +1663,7 @@ private: using NanotraceHR::keyValue; NanotraceHR::Tracer tracer{"insert exported type"_t, projectStorageCategory(), - keyValue("exported type", NanotraceHR::value(type))}; + keyValue("exported type", type)}; if (!type.moduleId) throw QmlDesigner::ModuleDoesNotExists{}; @@ -1694,8 +1695,8 @@ private: if (view.typeId != type.typeId) { NanotraceHR::Tracer tracer{"update exported type"_t, projectStorageCategory(), - keyValue("exported type", NanotraceHR::value(type)), - keyValue("exported type view", NanotraceHR::value(view))}; + keyValue("exported type", type), + keyValue("exported type view", view)}; handlePropertyDeclarationWithPropertyType(view.typeId, relinkablePropertyDeclarations); handleAliasPropertyDeclarationsWithPropertyType(view.typeId, @@ -1711,7 +1712,7 @@ private: auto remove = [&](const Storage::Synchronization::ExportedTypeView &view) { NanotraceHR::Tracer tracer{"remove exported type"_t, projectStorageCategory(), - keyValue("exported type view", NanotraceHR::value(view))}; + keyValue("exported type view", view)}; handlePropertyDeclarationWithPropertyType(view.typeId, relinkablePropertyDeclarations); handleAliasPropertyDeclarationsWithPropertyType(view.typeId, @@ -2012,7 +2013,7 @@ private: using NanotraceHR::keyValue; NanotraceHR::Tracer tracer{"insert import"_t, projectStorageCategory(), - keyValue("import", NanotraceHR::value(import)), + keyValue("import", import), keyValue("import kind", importKind), keyValue("source id", import.sourceId)}; @@ -2028,7 +2029,7 @@ private: NanotraceHR::Tracer tracer{"insert indirect import"_t, projectStorageCategory(), - keyValue("import", NanotraceHR::value(import)), + keyValue("import", import), keyValue("import kind", exportedImportKind)}; auto indirectImportId = insertDocumentImport(additionImport, @@ -2560,7 +2561,7 @@ private: using NanotraceHR::keyValue; NanotraceHR::Tracer tracer{"fetch imported type name id and type id"_t, projectStorageCategory(), - keyValue("impoted type name", NanotraceHR::value(typeName)), + keyValue("impoted type name", typeName), keyValue("source id", sourceId)}; TypeId typeId; @@ -2587,8 +2588,8 @@ private: using NanotraceHR::keyValue; NanotraceHR::Tracer tracer{"synchronize prototype and extension"_t, projectStorageCategory(), - keyValue("prototype", NanotraceHR::value(type.prototype)), - keyValue("extension", NanotraceHR::value(type.extension)), + keyValue("prototype", type.prototype), + keyValue("extension", type.extension), keyValue("type id", type.typeId), keyValue("source id", type.sourceId)}; @@ -2673,7 +2674,7 @@ private: NanotraceHR::Tracer tracer{"fetch imported type name id"_t, projectStorageCategory(), keyValue("imported type name", importedType.name), - keyValue("import", NanotraceHR::value(importedType.import)), + keyValue("import", importedType.import), keyValue("type name kind", "qualified exported"sv)}; ImportId importId = storage.fetchImportId(sourceId, importedType.import); diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorageinfotypes.h b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageinfotypes.h index 427c0ff8d61..4dd023ae9fa 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstorageinfotypes.h +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageinfotypes.h @@ -206,6 +206,17 @@ public: VersionNumber major; VersionNumber minor; }; + +template +void convertToString(String &string, const Version &version) +{ + using NanotraceHR::dictonary; + using NanotraceHR::keyValue; + auto dict = dictonary(keyValue("major version", version.major.value), + keyValue("minor version", version.minor.value)); + + convertToString(string, dict); +} } // namespace QmlDesigner::Storage namespace QmlDesigner::Storage::Info { diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstoragetypes.h b/src/plugins/qmldesigner/designercore/projectstorage/projectstoragetypes.h index 6199911497b..f3272a71157 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstoragetypes.h +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstoragetypes.h @@ -54,6 +54,17 @@ public: using Imports = std::vector; +template +void convertToString(String &string, const Import &import) +{ + using NanotraceHR::dictonary; + using NanotraceHR::keyValue; + auto dict = dictonary(keyValue("module id", import.moduleId), + keyValue("source id", import.sourceId), + keyValue("version", import.version)); + convertToString(string, dict); +} + namespace Synchronization { enum class TypeNameKind { Exported = 1, QualifiedExported = 2 }; @@ -274,6 +285,19 @@ public: using ExportedTypes = std::vector; +template +void convertToString(String &string, const ExportedType &exportedType) +{ + using NanotraceHR::dictonary; + using NanotraceHR::keyValue; + auto dict = dictonary(keyValue("name", exportedType.name), + keyValue("module id", exportedType.moduleId), + keyValue("type id", exportedType.typeId), + keyValue("version", exportedType.version)); + + convertToString(string, dict); +} + class ExportedTypeView { public: @@ -304,8 +328,59 @@ public: ExportedTypeNameId exportedTypeNameId; }; +template +void convertToString(String &string, const ExportedTypeView &exportedType) +{ + using NanotraceHR::dictonary; + using NanotraceHR::keyValue; + auto dict = dictonary(keyValue("name", exportedType.name), + keyValue("module id", exportedType.moduleId), + keyValue("type id", exportedType.typeId), + keyValue("version", exportedType.version), + keyValue("version", exportedType.exportedTypeNameId)); + + convertToString(string, dict); +} + using ImportedTypeName = std::variant; +template +void convertToString(String &string, const ImportedTypeName &typeName) +{ + using NanotraceHR::dictonary; + using NanotraceHR::keyValue; + + struct Dispatcher + { + static const QmlDesigner::Storage::Import &nullImport() + { + static QmlDesigner::Storage::Import import; + + return import; + } + + void operator()(const QmlDesigner::Storage::Synchronization::ImportedType &importedType) const + { + auto dict = dictonary(keyValue("name", importedType.name), keyValue("import", "empty")); + + convertToString(string, dict); + } + + void operator()( + const QmlDesigner::Storage::Synchronization::QualifiedImportedType &qualifiedImportedType) const + { + auto dict = dictonary(keyValue("name", qualifiedImportedType.name), + keyValue("import", qualifiedImportedType.import)); + + convertToString(string, dict); + } + + String &string; + }; + + std::visit(Dispatcher{string}, typeName); +} + class EnumeratorDeclaration { public: @@ -879,64 +954,3 @@ public: } // namespace Synchronization } // namespace QmlDesigner::Storage - -namespace NanotraceHR { - -inline auto value(const QmlDesigner::Storage::Version &version) -{ - return dictonary(keyValue("major version", version.major.value), - keyValue("minor version", version.minor.value)); -} - -inline auto value(const QmlDesigner::Storage::Import &import) -{ - return dictonary(keyValue("module id", import.moduleId), - keyValue("source id", import.sourceId), - keyValue("version", value(import.version))); -} - -inline auto value(const QmlDesigner::Storage::Synchronization::ExportedType &exportedType) -{ - return dictonary(keyValue("name", exportedType.name), - keyValue("module id", exportedType.moduleId), - keyValue("type id", exportedType.typeId), - keyValue("version", value(exportedType.version))); -} - -inline auto value(const QmlDesigner::Storage::Synchronization::ExportedTypeView &exportedType) -{ - return dictonary(keyValue("name", exportedType.name), - keyValue("module id", exportedType.moduleId), - keyValue("type id", exportedType.typeId), - keyValue("version", value(exportedType.version)), - keyValue("version", exportedType.exportedTypeNameId)); -} - -inline auto value(const QmlDesigner::Storage::Synchronization::ImportedTypeName &typeName) -{ - struct Dispatcher - { - static const QmlDesigner::Storage::Import &nullImport() - { - static QmlDesigner::Storage::Import import; - - return import; - } - - auto operator()(const QmlDesigner::Storage::Synchronization::ImportedType &importedType) const - { - return dictonary(keyValue("name", importedType.name), - keyValue("import", value(nullImport()))); - } - - auto operator()( - const QmlDesigner::Storage::Synchronization::QualifiedImportedType &qualifiedImportedType) const - { - return dictonary(keyValue("name", qualifiedImportedType.name), - keyValue("import", value(qualifiedImportedType.import))); - } - }; - - return std::visit(Dispatcher{}, typeName); -} -} // namespace NanotraceHR