aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/ApiExtractor/abstractmetatype.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-02-26 11:01:26 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-02-27 09:58:32 +0100
commitc3ed21d824a337fec35a76b00440affe7e9841a1 (patch)
tree05131a4662d4515e98cc2f767f60168214baf9f5 /sources/shiboken6/ApiExtractor/abstractmetatype.cpp
parentae72a51e871e95af5282c743c7498374bdae8c68 (diff)
shiboken6: Improve caching in AbstractMetaType::fromString()
Cache the unmodified string (typically containing the global prefix "::" in code snippets) as well. Pick-to: 6.6 Task-number: PYSIDE-2590 Change-Id: Iac1efbe19974080925b63cc819721462f75fda42 Reviewed-by: Adrian Herrmann <adrian.herrmann@qt.io> Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'sources/shiboken6/ApiExtractor/abstractmetatype.cpp')
-rw-r--r--sources/shiboken6/ApiExtractor/abstractmetatype.cpp14
1 files changed, 10 insertions, 4 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();
}