aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2021-02-01 01:03:40 +0200
committerAhmad Samir <a.samirh78@gmail.com>2021-02-06 16:28:53 +0200
commit081f559031fed7cde755e006b226cf06f33bd0f8 (patch)
treef6334b19630d6d9df9074b493c5eaa3c7914954e
parent5d0dac047384e1f46e2de57f9b9ebf4f6fde0e26 (diff)
downloadkconfig-081f559031fed7cde755e006b226cf06f33bd0f8.tar.gz
kconfig-081f559031fed7cde755e006b226cf06f33bd0f8.tar.bz2
General code cleanup
Fix some clazy warnings, and some other minor code optimisations. NO_CHANGELOG
-rw-r--r--autotests/kconfigtest.cpp2
-rw-r--r--autotests/kdesktopfiletest.cpp8
-rw-r--r--autotests/test_kconf_update.cpp8
-rw-r--r--src/core/kconfig.cpp2
-rw-r--r--src/core/kconfiggroup.cpp8
-rw-r--r--src/core/kconfigwatcher.cpp3
-rw-r--r--src/core/ksharedconfig.cpp2
-rw-r--r--src/kconfig_compiler/KConfigCodeGeneratorBase.cpp26
-rw-r--r--src/kconfig_compiler/KConfigHeaderGenerator.cpp27
-rw-r--r--src/kconfig_compiler/KConfigSourceGenerator.cpp26
-rw-r--r--src/kconfig_compiler/kconfig_compiler.cpp16
-rw-r--r--src/kreadconfig/kwriteconfig.cpp2
12 files changed, 58 insertions, 72 deletions
diff --git a/autotests/kconfigtest.cpp b/autotests/kconfigtest.cpp
index 6ab50b2f..23bcf195 100644
--- a/autotests/kconfigtest.cpp
+++ b/autotests/kconfigtest.cpp
@@ -513,7 +513,7 @@ void KConfigTest::testPath()
KConfigGroup sc3(&sc2, "Path Type");
QCOMPARE(sc3.readPathEntry("homepath", QString()), HOMEPATH);
QCOMPARE(sc3.readPathEntry("homepathescape", QString()), HOMEPATHESCAPE);
- QCOMPARE(sc3.entryMap()["homepath"], HOMEPATH);
+ QCOMPARE(sc3.entryMap().value("homepath"), HOMEPATH);
qputenv("WITHSLASH", "/a/");
{
diff --git a/autotests/kdesktopfiletest.cpp b/autotests/kdesktopfiletest.cpp
index e1b9c997..34391489 100644
--- a/autotests/kdesktopfiletest.cpp
+++ b/autotests/kdesktopfiletest.cpp
@@ -267,10 +267,10 @@ void KDesktopFileTest::testTryExecWithAuthorizeAction()
void KDesktopFileTest::testLocateLocal_data()
{
- QString systemConfigLocation = QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation).last();
- QString writableConfigLocation = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
- QString systemDataLocation = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).last();
- QString writableDataLocation = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
+ const QString systemConfigLocation = QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation).constLast();
+ const QString writableConfigLocation = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
+ const QString systemDataLocation = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).constLast();
+ const QString writableDataLocation = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
QTest::addColumn<QString>("path");
QTest::addColumn<QString>("result");
diff --git a/autotests/test_kconf_update.cpp b/autotests/test_kconf_update.cpp
index 52292083..ba716f28 100644
--- a/autotests/test_kconf_update.cpp
+++ b/autotests/test_kconf_update.cpp
@@ -331,9 +331,7 @@ void TestKConfUpdate::test()
std::unique_ptr<QTemporaryFile> updFile(writeUpdFile(updContent));
runKConfUpdate(updFile->fileName());
- QString updateInfo = QStringLiteral("%1:%2")
- .arg(updFile->fileName().section('/', -1))
- .arg(QTest::currentDataTag());
+ QString updateInfo = QStringLiteral("%1:%2").arg(updFile->fileName().section(QLatin1Char('/'), -1), QTest::currentDataTag());
QString newConfContentAfter = readFile(newConfPath);
if (shouldUpdateWork) {
@@ -627,9 +625,7 @@ void TestKConfUpdate::testScript()
runKConfUpdate(updFile->fileName());
- QString updateInfo = QStringLiteral("%1:%2")
- .arg(updFile->fileName().section('/', -1))
- .arg(QTest::currentDataTag());
+ QString updateInfo = QStringLiteral("%1:%2").arg(updFile->fileName().section(QLatin1Char('/'), -1), QTest::currentDataTag());
QString newConfContent = readFile(confPath);
expectedNewConfContent = expectedNewConfContent.arg(updateInfo);
QCOMPARE(newConfContent, expectedNewConfContent);
diff --git a/src/core/kconfig.cpp b/src/core/kconfig.cpp
index 2a3c614f..04608b0d 100644
--- a/src/core/kconfig.cpp
+++ b/src/core/kconfig.cpp
@@ -742,7 +742,7 @@ void KConfigPrivate::parseConfigFiles()
files << mBackend->filePath();
}
if (!isSimple()) {
- files = extraFiles.toList() + files;
+ files = QList<QString>(extraFiles.cbegin(), extraFiles.cend()) + files;
}
// qDebug() << "parsing local files" << files;
diff --git a/src/core/kconfiggroup.cpp b/src/core/kconfiggroup.cpp
index 14cbcab8..d900458f 100644
--- a/src/core/kconfiggroup.cpp
+++ b/src/core/kconfiggroup.cpp
@@ -1098,13 +1098,9 @@ void KConfigGroup::writeXdgListEntry(const char *key, const QStringList &list, W
// XXX List serialization being a separate layer from low-level escaping is
// probably a bug. No affected entries are defined, though.
- QStringList::ConstIterator it = list.constBegin();
- const QStringList::ConstIterator end = list.constEnd();
- for (; it != end; ++it) {
- QString val(*it);
+ for (QString val : list) { // clazy:exclude=range-loop
val.replace(QLatin1Char('\\'), QLatin1String("\\\\")).replace(QLatin1Char(';'), QLatin1String("\\;"));
- value += val;
- value += QLatin1Char(';');
+ value += val + QLatin1Char(';');
}
writeEntry(key, value, flags);
diff --git a/src/core/kconfigwatcher.cpp b/src/core/kconfigwatcher.cpp
index f63c39c1..c5aa6205 100644
--- a/src/core/kconfigwatcher.cpp
+++ b/src/core/kconfigwatcher.cpp
@@ -57,7 +57,8 @@ KConfigWatcher::KConfigWatcher(const KSharedConfig::Ptr &config):
QStringList watchedPaths;
watchedPaths << QLatin1Char('/') + d->m_config->name();
- for (const QString &file: d->m_config->additionalConfigSources()) {
+ const auto cfgSources = d->m_config->additionalConfigSources();
+ for (const QString &file : cfgSources) {
watchedPaths << QLatin1Char('/') + file;
}
if (d->m_config->openFlags() & KConfig::IncludeGlobals) {
diff --git a/src/core/ksharedconfig.cpp b/src/core/ksharedconfig.cpp
index 42b80fa7..cc6adeb9 100644
--- a/src/core/ksharedconfig.cpp
+++ b/src/core/ksharedconfig.cpp
@@ -77,7 +77,7 @@ KSharedConfigPtr KSharedConfig::openConfig(const QString &_fileName,
list->mainConfig = nullptr;
}
- for (auto cfg : qAsConst(*list)) {
+ for (auto *cfg : qAsConst(*list)) {
if (cfg->name() == fileName &&
cfg->d_ptr->openFlags == flags &&
cfg->locationType() == resType
diff --git a/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp b/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp
index 6bcd2911..3f308cbb 100644
--- a/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp
+++ b/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp
@@ -108,7 +108,7 @@ void KConfigCodeGeneratorBase::start()
void KConfigCodeGeneratorBase::addHeaders(const QStringList &headerList)
{
- for (auto include : qAsConst(headerList)) {
+ for (const auto &include : headerList) {
if (include.startsWith(QLatin1Char('"'))) {
m_stream << "#include " << include << '\n';
} else {
@@ -122,7 +122,8 @@ void KConfigCodeGeneratorBase::addHeaders(const QStringList &headerList)
void KConfigCodeGeneratorBase::beginNamespaces()
{
if (!m_cfg.nameSpace.isEmpty()) {
- for (const QString &ns : m_cfg.nameSpace.split(QStringLiteral("::"))) {
+ const auto nameSpaceList = m_cfg.nameSpace.split(QStringLiteral("::"));
+ for (const QString &ns : nameSpaceList) {
m_stream << "namespace " << ns << " {\n";
}
m_stream << '\n';
@@ -171,9 +172,6 @@ QString KConfigCodeGeneratorBase::memberAccessorBody(const CfgEntry *e, bool glo
void KConfigCodeGeneratorBase::memberImmutableBody(const CfgEntry *e, bool globalEnums)
{
- QString n = e->name;
- QString t = e->type;
-
stream() << whitespace() << "return " << m_this << "isImmutable( QStringLiteral( \"";
if (!e->param.isEmpty()) {
stream() << QString(e->paramName).replace(QLatin1String("$(") + e->param + QLatin1Char(')'), QLatin1String("%1")) << "\" ).arg( ";
@@ -192,15 +190,13 @@ void KConfigCodeGeneratorBase::memberImmutableBody(const CfgEntry *e, bool globa
}
stream() << " )";
} else {
- stream() << n << "\" )";
+ stream() << e->name << "\" )";
}
stream() << " );\n";
}
void KConfigCodeGeneratorBase::createIfSetLogic(const CfgEntry *e, const QString &varExpression)
{
- const QString n = e->name;
- const QString t = e->type;
const bool hasBody = !e->signalList.empty() || m_cfg.generateProperties;
m_stream << whitespace() << "if (";
@@ -208,7 +204,7 @@ void KConfigCodeGeneratorBase::createIfSetLogic(const CfgEntry *e, const QString
m_stream << "v != " << varExpression << " && ";
}
- const auto immutablefunction = immutableFunction(n, m_cfg.dpointer ? m_cfg.className : QString());
+ const auto immutablefunction = immutableFunction(e->name, m_cfg.dpointer ? m_cfg.className : QString{});
m_stream << "!" << m_this << immutablefunction << "(";
if (!e->param.isEmpty()) {
m_stream << " i ";
@@ -218,15 +214,14 @@ void KConfigCodeGeneratorBase::createIfSetLogic(const CfgEntry *e, const QString
void KConfigCodeGeneratorBase::memberMutatorBody(const CfgEntry *e)
{
- QString n = e->name;
- QString t = e->type;
// HACK: Don't open '{' manually, use startScope / endScope to automatically handle whitespace indentation.
if (!e->min.isEmpty()) {
- if (e->min != QLatin1String("0") || !isUnsigned(t)) { // skip writing "if uint<0" (#187579)
+ if (e->min != QLatin1String("0") || !isUnsigned(e->type)) { // skip writing "if uint<0" (#187579)
m_stream << whitespace() << "if (v < " << e->min << ")\n";
m_stream << whitespace() << "{\n";
- m_stream << whitespace(); addDebugMethod(m_stream, m_cfg, n);
+ m_stream << whitespace();
+ addDebugMethod(m_stream, m_cfg, e->name);
m_stream << ": value \" << v << \" is less than the minimum value of " << e->min << "\";\n";
m_stream << whitespace() << " v = " << e->min << ";\n";
m_stream << whitespace() << "}\n";
@@ -237,13 +232,14 @@ void KConfigCodeGeneratorBase::memberMutatorBody(const CfgEntry *e)
m_stream << '\n';
m_stream << whitespace() << "if (v > " << e->max << ")\n";
m_stream << whitespace() << "{\n";
- m_stream << whitespace(); addDebugMethod(m_stream, m_cfg, n);
+ m_stream << whitespace();
+ addDebugMethod(m_stream, m_cfg, e->name);
m_stream << ": value \" << v << \" is greater than the maximum value of " << e->max << "\";\n";
m_stream << whitespace() << " v = " << e->max << ";\n";
m_stream << whitespace() << "}\n\n";
}
- const QString varExpression = m_this + varPath(n, m_cfg) + (e->param.isEmpty() ? QString() : QStringLiteral("[i]"));
+ const QString varExpression = m_this + varPath(e->name, m_cfg) + (e->param.isEmpty() ? QString{} : QStringLiteral("[i]"));
// TODO: Remove this `hasBody` logic, always use an '{' for the if.
const bool hasBody = !e->signalList.empty() || m_cfg.generateProperties;
diff --git a/src/kconfig_compiler/KConfigHeaderGenerator.cpp b/src/kconfig_compiler/KConfigHeaderGenerator.cpp
index 43a80a60..7829ab67 100644
--- a/src/kconfig_compiler/KConfigHeaderGenerator.cpp
+++ b/src/kconfig_compiler/KConfigHeaderGenerator.cpp
@@ -56,13 +56,8 @@ void KConfigHeaderGenerator::doClassDefinition()
createConstructor();
createDestructor();
- for (auto *entry : parseResult.entries) {
- const QString n = entry->name;
- const QString t = entry->type;
-
- const QString returnType = (cfg().useEnumTypes && t == QLatin1String("Enum"))
- ? enumType(entry, cfg().globalEnums)
- : cppType(t);
+ for (const auto *entry : qAsConst(parseResult.entries)) {
+ const QString returnType = (cfg().useEnumTypes && entry->type == QLatin1String("Enum")) ? enumType(entry, cfg().globalEnums) : cppType(entry->type);
createSetters(entry);
createProperties(entry, returnType);
@@ -90,7 +85,7 @@ void KConfigHeaderGenerator::doClassDefinition()
}
// Class Parameters
- for (const auto &parameter : parseResult.parameters) {
+ for (const auto &parameter : qAsConst(parseResult.parameters)) {
stream() << whitespace() << "" << cppType(parameter.type) << " mParam" << parameter.name << ";\n";
}
@@ -135,7 +130,7 @@ void KConfigHeaderGenerator::startHeaderGuards()
{
const bool hasNamespace = !cfg().nameSpace.isEmpty();
const QString namespaceName = QString(QString(cfg().nameSpace).replace(QLatin1String("::"), QLatin1String("_"))).toUpper();
- const QString namespaceStr = hasNamespace ? namespaceName + QLatin1Char('_') : QStringLiteral("");
+ const QString namespaceStr = hasNamespace ? namespaceName + QLatin1Char('_') : QString{};
const QString defineName = namespaceStr + cfg().className.toUpper() + QStringLiteral("_H");
stream() << "#ifndef " << defineName << '\n';
@@ -210,7 +205,7 @@ void KConfigHeaderGenerator::implementEnums()
return;
}
- for (const auto entry : parseResult.entries) {
+ for (const auto *entry : qAsConst(parseResult.entries)) {
const CfgEntry::Choices &choices = entry->choices;
const QStringList values = entry->paramValues;
@@ -259,7 +254,7 @@ void KConfigHeaderGenerator::createSignals()
<< "\n\n";
stream() << " Q_SIGNALS:";
- for (const Signal &signal : parseResult.signalList) {
+ for (const Signal &signal : qAsConst(parseResult.signalList)) {
stream() << '\n';
if (!signal.label.isEmpty()) {
stream() << whitespace() << "/**\n";
@@ -272,7 +267,7 @@ void KConfigHeaderGenerator::createSignals()
Param argument = *it;
QString type = param(argument.type);
if (cfg().useEnumTypes && argument.type == QLatin1String("Enum")) {
- for (auto *entry : parseResult.entries) {
+ for (const auto *entry : qAsConst(parseResult.entries)) {
if (entry->name == argument.name) {
type = enumType(entry, cfg().globalEnums);
break;
@@ -301,7 +296,7 @@ void KConfigHeaderGenerator::createDPointer()
// use a private class for both member variables and items
stream() << " private:\n";
- for (const auto &entry : parseResult.entries) {
+ for (const auto *entry : qAsConst(parseResult.entries)) {
if (cfg().allDefaultGetters || cfg().defaultGetters.contains(entry->name)) {
stream() << whitespace() << "";
if (cfg().staticAccessors) {
@@ -337,7 +332,7 @@ void KConfigHeaderGenerator::createConstructor()
}
bool first = true;
- for (const auto parameter : parseResult.parameters) {
+ for (const auto &parameter : qAsConst(parseResult.parameters)) {
if (first) {
first = false;
} else {
@@ -601,7 +596,7 @@ void KConfigHeaderGenerator::createNonDPointerHelpers()
}
QString group;
- for (auto *entry : parseResult.entries) {
+ for (const auto *entry : qAsConst(parseResult.entries)) {
if (entry->group != group) {
group = entry->group;
stream() << '\n';
@@ -628,7 +623,7 @@ void KConfigHeaderGenerator::createNonDPointerHelpers()
stream() << "\n private:\n";
if (cfg().itemAccessors) {
- for (auto *entry : parseResult.entries) {
+ for (const auto *entry : qAsConst(parseResult.entries)) {
stream() << whitespace() << "Item" << itemType(entry->type) << " *" << itemVar(entry, cfg());
if (!entry->param.isEmpty()) {
stream() << QStringLiteral("[%1]").arg(entry->paramMax + 1);
diff --git a/src/kconfig_compiler/KConfigSourceGenerator.cpp b/src/kconfig_compiler/KConfigSourceGenerator.cpp
index 97db81ba..663a138f 100644
--- a/src/kconfig_compiler/KConfigSourceGenerator.cpp
+++ b/src/kconfig_compiler/KConfigSourceGenerator.cpp
@@ -15,12 +15,8 @@
#include <QRegularExpression>
-KConfigSourceGenerator::KConfigSourceGenerator(
- const QString &inputFile,
- const QString &baseDir,
- const KConfigParameters &cfg,
- ParseResult &result)
- : KConfigCodeGeneratorBase(inputFile, baseDir, baseDir + cfg.baseName + QLatin1Char('.') + cfg.sourceExtension, cfg, result)
+KConfigSourceGenerator::KConfigSourceGenerator(const QString &inputFile, const QString &baseDir, const KConfigParameters &cfg, ParseResult &parseResult)
+ : KConfigCodeGeneratorBase(inputFile, baseDir, baseDir + cfg.baseName + QLatin1Char('.') + cfg.sourceExtension, cfg, parseResult)
{
}
@@ -96,7 +92,7 @@ void KConfigSourceGenerator::createPrivateDPointerImplementation()
stream() << " public:\n";
// Create Members
- for (auto *entry : parseResult.entries) {
+ for (const auto *entry : qAsConst(parseResult.entries)) {
if (entry->group != group) {
group = entry->group;
stream() << '\n';
@@ -111,7 +107,7 @@ void KConfigSourceGenerator::createPrivateDPointerImplementation()
stream() << "\n // items\n";
// Create Items.
- for (auto *entry : parseResult.entries) {
+ for (const auto *entry : qAsConst(parseResult.entries)) {
const QString declType = entry->signalList.isEmpty()
? QString(cfg().inherits + QStringLiteral("::Item") + itemType(entry->type))
: QStringLiteral("KConfigCompilerSignallingItem");
@@ -192,7 +188,7 @@ void KConfigSourceGenerator::createSingletonImplementation()
void KConfigSourceGenerator::createPreamble()
{
QString cppPreamble;
- for (const auto entry : parseResult.entries) {
+ for (const auto *entry : qAsConst(parseResult.entries)) {
if (entry->paramValues.isEmpty()) {
continue;
}
@@ -257,7 +253,7 @@ void KConfigSourceGenerator::createParentConstructorCall()
void KConfigSourceGenerator::createInitializerList()
{
- for (const auto &parameter : parseResult.parameters) {
+ for (const auto &parameter : qAsConst(parseResult.parameters)) {
stream() << " , mParam" << parameter.name << "(" << parameter.name << ")\n";
}
@@ -480,7 +476,7 @@ void KConfigSourceGenerator::doConstructor()
stream() << '\n';
}
- for (auto *entry : parseResult.entries) {
+ for (const auto *entry : qAsConst(parseResult.entries)) {
handleCurrentGroupChange(entry);
const QString key = paramString(entry->key, parseResult.parameters);
@@ -591,7 +587,7 @@ void KConfigSourceGenerator::doGetterSetterDPointerMode()
}
// setters and getters go in Cpp if in dpointer mode
- for (auto *entry : parseResult.entries) {
+ for (const auto *entry : qAsConst(parseResult.entries)) {
createSetterDPointerMode(entry);
createGetterDPointerMode(entry);
createImmutableGetterDPointerMode(entry);
@@ -603,7 +599,7 @@ void KConfigSourceGenerator::doGetterSetterDPointerMode()
void KConfigSourceGenerator::createDefaultValueGetterSetter()
{
// default value getters always go in Cpp
- for (auto *entry : parseResult.entries) {
+ for (const auto *entry : qAsConst(parseResult.entries)) {
QString n = entry->name;
QString t = entry->type;
@@ -645,7 +641,7 @@ void KConfigSourceGenerator::createNonModifyingSignalsHelper()
startScope();
stream() << " const bool res = " << cfg().inherits << "::usrSave();\n";
stream() << " if (!res) return false;\n\n";
- for (const Signal &signal : parseResult.signalList) {
+ for (const Signal &signal : qAsConst(parseResult.signalList)) {
if (signal.modify) {
continue;
}
@@ -696,7 +692,7 @@ void KConfigSourceGenerator::createSignalFlagsHandler()
if (!parseResult.signalList.isEmpty())
stream() << '\n';
- for (const Signal &signal : parseResult.signalList) {
+ for (const Signal &signal : qAsConst(parseResult.signalList)) {
if (signal.modify) {
stream() << " if ( flags & " << signalEnumName(signal.name) << " ) {\n";
stream() << " Q_EMIT " << signal.name << "();\n";
diff --git a/src/kconfig_compiler/kconfig_compiler.cpp b/src/kconfig_compiler/kconfig_compiler.cpp
index 4f9fa3f2..a7ecd83e 100644
--- a/src/kconfig_compiler/kconfig_compiler.cpp
+++ b/src/kconfig_compiler/kconfig_compiler.cpp
@@ -371,20 +371,26 @@ QString defaultValue(const QString &t)
QString itemType(const QString &type)
{
- QString t;
+ if (type.isEmpty()) {
+ return QString{};
+ }
- t = type;
- t.replace(0, 1, t.left(1).toUpper());
+ QString str = type;
+ str[0] = str.at(0).toUpper();
- return t;
+ return str;
}
QString itemDeclaration(const CfgEntry *e, const KConfigParameters &cfg)
{
+ if (e->name.isEmpty()) {
+ return QString{};
+ }
+
const QString type = cfg.inherits + "::Item" + itemType(e->type);
QString fCap = e->name;
- fCap[0] = fCap[0].toUpper();
+ fCap[0] = fCap.at(0).toUpper();
const QString argSuffix = (!e->param.isEmpty()) ? (QStringLiteral("[%1]").arg(e->paramMax + 1)) : QString();
QString result;
diff --git a/src/kreadconfig/kwriteconfig.cpp b/src/kreadconfig/kwriteconfig.cpp
index c5ad5689..8befa56d 100644
--- a/src/kreadconfig/kwriteconfig.cpp
+++ b/src/kreadconfig/kwriteconfig.cpp
@@ -38,7 +38,7 @@ int main(int argc, char **argv)
QString value;
if (del) {
- value = QStringLiteral("");
+ value = QString{};
} else if (parser.positionalArguments().isEmpty()) {
parser.showHelp(1);
} else {