aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedrich W. H. Kossebau <kossebau@kde.org>2021-11-14 19:26:34 +0100
committerFriedrich W. H. Kossebau <kossebau@kde.org>2021-11-14 19:26:34 +0100
commitc3be6d02f6c061707c6d93e06889a2e56b994d87 (patch)
tree413f81904db72616b064923c6a6d1fa021675af4
parent473a9137db305ea69cb4b40f23ed679c90c4b475 (diff)
downloadkconfig-c3be6d02f6c061707c6d93e06889a2e56b994d87.tar.gz
kconfig-c3be6d02f6c061707c6d93e06889a2e56b994d87.tar.bz2
Avoid some allocations by QString/QByteArray's toLower()
NO_CHANGELOG
-rw-r--r--src/core/kauthorized.cpp2
-rw-r--r--src/core/kconfiggroup.cpp12
-rw-r--r--src/core/kcoreconfigskeleton.cpp4
-rw-r--r--src/gui/kconfigloader.cpp2
-rw-r--r--src/kconf_update/kconf_update.cpp11
5 files changed, 19 insertions, 12 deletions
diff --git a/src/core/kauthorized.cpp b/src/core/kauthorized.cpp
index aad23949..66a2be23 100644
--- a/src/core/kauthorized.cpp
+++ b/src/core/kauthorized.cpp
@@ -332,7 +332,7 @@ KCONFIGCORE_EXPORT void loadUrlActionRestrictions(const KConfigGroup &cg)
const QString urlProt = rule[4];
const QString urlHost = rule[5];
QString urlPath = rule[6];
- const bool bEnabled = (rule[7].toLower() == QLatin1String("true"));
+ const bool bEnabled = (rule[7].compare(QLatin1String("true"), Qt::CaseInsensitive) == 0);
if (refPath.startsWith(QLatin1String("$HOME"))) {
refPath.replace(0, 5, QDir::homePath());
diff --git a/src/core/kconfiggroup.cpp b/src/core/kconfiggroup.cpp
index be1f2b0e..24a8ccfd 100644
--- a/src/core/kconfiggroup.cpp
+++ b/src/core/kconfiggroup.cpp
@@ -26,6 +26,8 @@
#include <QTextStream>
#include <QUrl>
+#include <algorithm>
+#include <array>
#include <math.h>
#include <stdlib.h>
@@ -234,11 +236,11 @@ QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray &val
case QMetaType::QByteArray:
return value;
case QMetaType::Bool: {
- const QByteArray lower(value.toLower());
- if (lower == "false" || lower == "no" || lower == "off" || lower == "0") {
- return false;
- }
- return true;
+ static const std::array<const char *, 4> negatives = {"false", "no", "off", "0"};
+
+ return std::all_of(negatives.begin(), negatives.end(), [value](const char *negativeString) {
+ return value.compare(negativeString, Qt::CaseInsensitive) != 0;
+ });
}
case QMetaType::Double:
case QMetaType::Float:
diff --git a/src/core/kcoreconfigskeleton.cpp b/src/core/kcoreconfigskeleton.cpp
index f8097055..030039fc 100644
--- a/src/core/kcoreconfigskeleton.cpp
+++ b/src/core/kcoreconfigskeleton.cpp
@@ -608,10 +608,10 @@ void KCoreConfigSkeleton::ItemEnum::readConfig(KConfig *config)
} else {
int i = 0;
mReference = -1;
- QString tmp = cg.readEntry(mKey, QString()).toLower();
+ const QString entryString = cg.readEntry(mKey, QString());
for (auto it = mChoices.cbegin(); it != mChoices.cend(); ++it, ++i) {
QString choiceName = (*it).name;
- if (valueForChoice(choiceName).toLower() == tmp) {
+ if (valueForChoice(choiceName).compare(entryString, Qt::CaseInsensitive) == 0) {
mReference = i;
break;
}
diff --git a/src/gui/kconfigloader.cpp b/src/gui/kconfigloader.cpp
index ac39a12f..08365f17 100644
--- a/src/gui/kconfigloader.cpp
+++ b/src/gui/kconfigloader.cpp
@@ -172,7 +172,7 @@ void ConfigLoaderHandler::addItem()
KConfigSkeletonItem *item = nullptr;
if (m_type == QLatin1String("bool")) {
- bool defaultValue = m_default.toLower() == QLatin1String("true");
+ const bool defaultValue = caseInsensitiveCompare(m_default, QLatin1String("true"));
item = m_config->addItemBool(m_name, *d->newBool(), defaultValue, m_key);
} else if (m_type == QLatin1String("color")) {
item = m_config->addItemColor(m_name, *d->newColor(), QColor(m_default), m_key);
diff --git a/src/kconf_update/kconf_update.cpp b/src/kconf_update/kconf_update.cpp
index 8cbbc3c3..0e9744a0 100644
--- a/src/kconf_update/kconf_update.cpp
+++ b/src/kconf_update/kconf_update.cpp
@@ -35,6 +35,11 @@
// the file.
#define qCDebugFile(CATEGORY) qCDebug(CATEGORY) << m_currentFilename << ':' << m_lineCount << ":'" << m_line << "': "
+static bool caseInsensitiveCompare(const QStringView &a, const QLatin1String &b)
+{
+ return a.compare(b, Qt::CaseInsensitive) == 0;
+}
+
class KonfUpdate
{
public:
@@ -701,11 +706,11 @@ void KonfUpdate::gotOptions(const QString &_options)
{
const QStringList options = _options.split(QLatin1Char{','});
for (const auto &opt : options) {
- const auto normalizedOpt = opt.toLower().trimmed();
+ const auto normalizedOpt = QStringView(opt).trimmed();
- if (normalizedOpt == QLatin1String("copy")) {
+ if (caseInsensitiveCompare(normalizedOpt, QLatin1String("copy"))) {
m_bCopy = true;
- } else if (normalizedOpt == QLatin1String("overwrite")) {
+ } else if (caseInsensitiveCompare(normalizedOpt, QLatin1String("overwrite"))) {
m_bOverwrite = true;
}
}