aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/ApiExtractor/typesystem.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2017-08-28 14:45:11 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2017-08-29 14:22:12 +0000
commitdd4d94ea9210386ae86ee5f3601e3e7541f18811 (patch)
tree8fa352482c21cc363de5902fec4f4fbe07b34f58 /sources/shiboken2/ApiExtractor/typesystem.cpp
parent64c083a8e4056fa2330e3db06505269803ad2702 (diff)
Refactor TypeEntry::isCppPrimitive()
Introduce a helper function returning a sorted string vector to avoid converting each type string to a QByteArray. Change-Id: If9036d6251f5cc8d83ae13c8b5c3f731a6738657 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'sources/shiboken2/ApiExtractor/typesystem.cpp')
-rw-r--r--sources/shiboken2/ApiExtractor/typesystem.cpp31
1 files changed, 18 insertions, 13 deletions
diff --git a/sources/shiboken2/ApiExtractor/typesystem.cpp b/sources/shiboken2/ApiExtractor/typesystem.cpp
index 0f35e2dd6..6ba609333 100644
--- a/sources/shiboken2/ApiExtractor/typesystem.cpp
+++ b/sources/shiboken2/ApiExtractor/typesystem.cpp
@@ -33,6 +33,7 @@
#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtCore/QRegularExpression>
+#include <QtCore/QSet>
#include <QtCore/QXmlStreamAttributes>
#include <QtCore/QXmlStreamReader>
@@ -2568,9 +2569,19 @@ QString ContainerTypeEntry::typeName() const
}
}
-static bool strLess(const char* a, const char* b)
+static const QSet<QString> &primitiveCppTypes()
{
- return ::strcmp(a, b) < 0;
+ static QSet<QString> result;
+ if (result.isEmpty()) {
+ static const char *cppTypes[] = {
+ "bool", "char", "double", "float", "int",
+ "long", "long long", "short",
+ "wchar_t"
+ };
+ for (const char *cppType : cppTypes)
+ result.insert(QLatin1String(cppType));
+ }
+ return result;
}
bool TypeEntry::isCppPrimitive() const
@@ -2578,19 +2589,13 @@ bool TypeEntry::isCppPrimitive() const
if (!isPrimitive())
return false;
- const PrimitiveTypeEntry *referencedType =
- static_cast<const PrimitiveTypeEntry *>(this)->basicReferencedTypeEntry();
- QByteArray typeName = (referencedType ? referencedType->name() : m_name).toUtf8();
-
- if (typeName.contains(' ') || m_type == VoidType)
+ if (m_type == VoidType)
return true;
- // Keep this sorted!!
- static const char* cppTypes[] = { "bool", "char", "double", "float", "int", "long", "long long", "short", "wchar_t" };
- const int N = sizeof(cppTypes)/sizeof(char*);
-
- const char** res = qBinaryFind(&cppTypes[0], &cppTypes[N], typeName.constData(), strLess);
- return res != &cppTypes[N];
+ const PrimitiveTypeEntry *referencedType =
+ static_cast<const PrimitiveTypeEntry *>(this)->basicReferencedTypeEntry();
+ const QString &typeName = referencedType ? referencedType->name() : m_name;
+ return typeName.contains(QLatin1Char(' ')) || primitiveCppTypes().contains(typeName);
}
// Again, stuff to avoid ABI breakage.