From da84941375d8301d9f22df1fa3753571de005c64 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Fri, 2 Sep 2022 15:46:18 +0200 Subject: [PATCH] QMimeMagicRule: use qOffsetStringArray for storing types Each element of the array corresponds to an item in QMimeMagicRule::Type enum, so dropped the last empty string of the array which is not used. Change-Id: I4786afaa58287c26d4525180fe6fa6891ddcde26 Reviewed-by: Thiago Macieira --- src/corelib/mimetypes/qmimemagicrule.cpp | 32 +++++++++++------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/corelib/mimetypes/qmimemagicrule.cpp b/src/corelib/mimetypes/qmimemagicrule.cpp index 8681de6f44..b1019afc84 100644 --- a/src/corelib/mimetypes/qmimemagicrule.cpp +++ b/src/corelib/mimetypes/qmimemagicrule.cpp @@ -12,31 +12,29 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace Qt::StringLiterals; // in the same order as Type! -static const char magicRuleTypes_string[] = - "invalid\0" - "string\0" - "host16\0" - "host32\0" - "big16\0" - "big32\0" - "little16\0" - "little32\0" - "byte\0" - "\0"; - -static const int magicRuleTypes_indices[] = { - 0, 8, 15, 22, 29, 35, 41, 50, 59, 64, 0 -}; +static constexpr auto magicRuleTypes = qOffsetStringArray( + "invalid", + "string", + "host16", + "host32", + "big16", + "big32", + "little16", + "little32", + "byte" +); QMimeMagicRule::Type QMimeMagicRule::type(const QByteArray &theTypeName) { for (int i = String; i <= Byte; ++i) { - if (theTypeName == magicRuleTypes_string + magicRuleTypes_indices[i]) + if (theTypeName == magicRuleTypes.at(i)) return Type(i); } return Invalid; @@ -44,7 +42,7 @@ QMimeMagicRule::Type QMimeMagicRule::type(const QByteArray &theTypeName) QByteArray QMimeMagicRule::typeName(QMimeMagicRule::Type theType) { - return magicRuleTypes_string + magicRuleTypes_indices[theType]; + return magicRuleTypes.at(theType); } bool QMimeMagicRule::operator==(const QMimeMagicRule &other) const