diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-02-26 11:01:26 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-02-27 11:10:53 +0000 |
commit | 2bc6c255de159f28b782d1573be4776f193dfefa (patch) | |
tree | db2abf63a59a8f9ae5f397bcb5bc3811f3c2af9c | |
parent | 3082853a0214bf4782e30bc740f1694d5a012542 (diff) |
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 <adrian.herrmann@qt.io>
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
(cherry picked from commit c3ed21d824a337fec35a76b00440affe7e9841a1)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | sources/shiboken6/ApiExtractor/abstractmetatype.cpp | 14 | ||||
-rw-r--r-- | 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<QString, AbstractMetaType>; Q_GLOBAL_STATIC(AbstractMetaTypeCache, metaTypeFromStringCache) std::optional<AbstractMetaType> -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<AbstractMetaType> - 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. |