diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2021-09-29 19:08:15 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2021-11-03 14:54:37 -0700 |
commit | 2c2c6de85ae41d09063f3c68a42522e3d74ad8fa (patch) | |
tree | 50d56fbef5ed5c0b3dbcf3d35c9bbba93a758e5f /src/corelib/global/qlibraryinfo.cpp | |
parent | 95cc652e1afe7a6edd17cd251fc8ba1eb639eb4f (diff) |
qlibraryinfo.cpp: use qOffsetStringArray for qtConfEntries
Beats a manual array with too wide strings. I thought even to simply
replace this with a switch (loc)... it's not like this is
performance-critical code, given it uses QString.
Change-Id: I2bbf422288924c198645fffd16a977778ff8d52d
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/corelib/global/qlibraryinfo.cpp')
-rw-r--r-- | src/corelib/global/qlibraryinfo.cpp | 72 |
1 files changed, 35 insertions, 37 deletions
diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index a2bf7599fe..b77df87f91 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -304,35 +304,6 @@ QVersionNumber QLibraryInfo::version() noexcept return QVersionNumber(QT_VERSION_MAJOR, QT_VERSION_MINOR, QT_VERSION_PATCH); } -/* - * To add a new entry in QLibraryInfo::LibraryPath, add it to the enum - * in qtbase/src/corelib/global/qlibraryinfo.h and: - * - add its relative path in the qtConfEntries[] array below - * (the key is what appears in a qt.conf file) - */ - -static const struct { - char key[19], value[13]; -} qtConfEntries[] = { - { "Prefix", "." }, - { "Documentation", "doc" }, // should be ${Data}/doc - { "Headers", "include" }, - { "Libraries", "lib" }, -#ifdef Q_OS_WIN - { "LibraryExecutables", "bin" }, -#else - { "LibraryExecutables", "libexec" }, // should be ${ArchData}/libexec -#endif - { "Binaries", "bin" }, - { "Plugins", "plugins" }, // should be ${ArchData}/plugins - { "Qml2Imports", "qml" }, // should be ${ArchData}/qml - { "ArchData", "." }, - { "Data", "." }, - { "Translations", "translations" }, // should be ${Data}/translations - { "Examples", "examples" }, - { "Tests", "tests" }, -}; - static QString prefixFromAppDirHelper() { QString appDir; @@ -515,17 +486,44 @@ static QString getPrefix() void QLibraryInfoPrivate::keyAndDefault(QLibraryInfo::LibraryPath loc, QString *key, QString *value) { - if (unsigned(loc) < sizeof(qtConfEntries)/sizeof(qtConfEntries[0])) { - *key = QLatin1String(qtConfEntries[loc].key); - *value = QLatin1String(qtConfEntries[loc].value); - } + /* + * To add a new entry in QLibraryInfo::LibraryPath, add it to the enum + * in qtbase/src/corelib/global/qlibraryinfo.h and: + * - add its relative path in the qtConfEntries[] array below + * (the key is what appears in a qt.conf file) + */ + static constexpr auto qtConfEntries = qOffsetStringArray( + "Prefix", ".", + "Documentation", "doc", // should be ${Data}/doc + "Headers", "include", + "Libraries", "lib", +#ifdef Q_OS_WIN + "LibraryExecutables", "bin", +#else + "LibraryExecutables", "libexec", // should be ${ArchData}/libexec +#endif + "Binaries", "bin", + "Plugins", "plugins", // should be ${ArchData}/plugins + "Qml2Imports", "qml", // should be ${ArchData}/qml + "ArchData", ".", + "Data", ".", + "Translations", "translations", // should be ${Data}/translations + "Examples", "examples", + "Tests", "tests" + ); + static constexpr QByteArrayView dot = qtConfEntries.viewAt(1); + static_assert(dot.size() == 1); + static_assert(dot[0] == '.'); + + if (int(loc) < qtConfEntries.count()) { + *key = QLatin1String(qtConfEntries.viewAt(loc * 2)); + *value = QLatin1String(qtConfEntries.viewAt(loc * 2 + 1)); #ifndef Q_OS_WIN // On Windows we use the registry - else if (loc == QLibraryInfo::SettingsPath) { + } else if (loc == QLibraryInfo::SettingsPath) { *key = QLatin1String("Settings"); - *value = QLatin1String("."); - } + *value = QLatin1String(dot); #endif - else { + } else { key->clear(); value->clear(); } |