From 2bc6c255de159f28b782d1573be4776f193dfefa Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 26 Feb 2024 11:01:26 +0100 Subject: shiboken6: Improve caching in AbstractMetaType::fromString() Cache the unmodified string (typically containing the global prefix "::" in code snippets) as well. Task-number: PYSIDE-2590 Change-Id: Iac1efbe19974080925b63cc819721462f75fda42 Reviewed-by: Adrian Herrmann Reviewed-by: Shyamnath Premnadh (cherry picked from commit c3ed21d824a337fec35a76b00440affe7e9841a1) Reviewed-by: Qt Cherry-pick Bot --- sources/shiboken6/ApiExtractor/abstractmetatype.cpp | 14 ++++++++++---- sources/shiboken6/ApiExtractor/abstractmetatype.h | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/sources/shiboken6/ApiExtractor/abstractmetatype.cpp b/sources/shiboken6/ApiExtractor/abstractmetatype.cpp index d9f5bde41..8a2a83c94 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetatype.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetatype.cpp @@ -948,14 +948,18 @@ using AbstractMetaTypeCache = QHash; Q_GLOBAL_STATIC(AbstractMetaTypeCache, metaTypeFromStringCache) std::optional -AbstractMetaType::fromString(QString typeSignature, QString *errorMessage) +AbstractMetaType::fromString(const QString &typeSignatureIn, QString *errorMessage) { - typeSignature = typeSignature.trimmed(); + auto &cache = *metaTypeFromStringCache(); + auto it = cache.find(typeSignatureIn); + if (it != cache.end()) + return it.value(); + + QString typeSignature = typeSignatureIn.trimmed(); if (typeSignature.startsWith(u"::")) typeSignature.remove(0, 2); - auto &cache = *metaTypeFromStringCache(); - auto it = cache.find(typeSignature); + it = cache.find(typeSignature); if (it == cache.end()) { auto metaType = AbstractMetaBuilder::translateType(typeSignature, nullptr, {}, errorMessage); @@ -965,6 +969,8 @@ AbstractMetaType::fromString(QString typeSignature, QString *errorMessage) return {}; } it = cache.insert(typeSignature, metaType.value()); + if (typeSignature != typeSignatureIn) + cache.insert(typeSignatureIn, metaType.value()); } return it.value(); } diff --git a/sources/shiboken6/ApiExtractor/abstractmetatype.h b/sources/shiboken6/ApiExtractor/abstractmetatype.h index dd3d96bf8..96dbb296a 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetatype.h +++ b/sources/shiboken6/ApiExtractor/abstractmetatype.h @@ -188,7 +188,7 @@ public: /// \param typeSignature The string describing the type to be built. /// \return A new AbstractMetaType object or nullopt in case of failure. static std::optional - fromString(QString typeSignature, QString *errorMessage = nullptr); + fromString(const QString &typeSignatureIn, QString *errorMessage = nullptr); /// Creates an AbstractMetaType object from a TypeEntry. static AbstractMetaType fromTypeEntry(const TypeEntryCPtr &typeEntry); /// Creates an AbstractMetaType object from an AbstractMetaClass. -- cgit v1.2.3