diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-12-18 17:16:41 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-12-20 17:40:44 +0100 |
commit | 3139c8dddf9dfb0e935cd03b3d539541fdf0edf0 (patch) | |
tree | 854e6b0db01ea267334ead833843c3bf2c748c50 | |
parent | 9f7741c021e7fb06c3c4f2a1782594951362940f (diff) |
shiboken6: Refactor the class find algorithm
Search for target lang name if there is a dot present
and do not search for unqualified names if there is a "::"
in the name.
Use iterators to prepare for the use of different container types.
Pick-to: 6.0
Change-Id: I4722cfacb4173c84035038c667ec1aaeb049c713
Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r-- | sources/shiboken6/ApiExtractor/abstractmetalang.cpp | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetalang.cpp b/sources/shiboken6/ApiExtractor/abstractmetalang.cpp index 32befc400..72d36bae7 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetalang.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetalang.cpp @@ -1342,33 +1342,44 @@ std::optional<AbstractMetaEnumValue> return {}; } -/*! - * Searches the list after a class that mathces \a name; either as - * C++, Target language base name or complete Target language package.class name. - */ +/// Searches the list after a class that matches \a name; either as C++, +/// Target language base name or complete Target language package.class name. -AbstractMetaClass *AbstractMetaClass::findClass(const AbstractMetaClassList &classes, - const QString &name) +template <class It> +static It findClassHelper(It begin, It end, const QString &name) { - if (name.isEmpty()) - return nullptr; + if (name.isEmpty() || begin == end) + return end; - for (AbstractMetaClass *c : classes) { - if (c->qualifiedCppName() == name) - return c; + if (name.contains(u'.')) { // Search target lang name + for (auto it = begin; it != end; ++it) { + if ((*it)->fullName() == name) + return it; + } + return end; } - for (AbstractMetaClass *c : classes) { - if (c->fullName() == name) - return c; + for (auto it = begin; it != end; ++it) { + if ((*it)->qualifiedCppName() == name) + return it; } - for (AbstractMetaClass *c : classes) { - if (c->name() == name) - return c; + if (name.contains(u"::")) // Qualified, cannot possibly match name + return end; + + for (auto it = begin; it != end; ++it) { + if ((*it)->name() == name) + return it; } - return nullptr; + return end; +} + +AbstractMetaClass *AbstractMetaClass::findClass(const AbstractMetaClassList &classes, + const QString &name) +{ + auto it =findClassHelper(classes.cbegin(), classes.cend(), name); + return it != classes.cend() ? *it : nullptr; } AbstractMetaClass *AbstractMetaClass::findClass(const AbstractMetaClassList &classes, |