From 9d87348260316af729892c58bc29f159a173abf1 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Tue, 23 Feb 2021 00:37:11 +0200 Subject: Minor code optimisation - Use more range-for loops where appropriate - Use auto instead of the usually-long iterator type names - Use cbegin/cend(), to match the std:: containers, less confusion - Use qDeleteAll instead of a for loop - Make a QRE with a long-ish pattern static NO_CHANGELOG --- src/kconfig_compiler/KConfigXmlParser.cpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'src/kconfig_compiler/KConfigXmlParser.cpp') diff --git a/src/kconfig_compiler/KConfigXmlParser.cpp b/src/kconfig_compiler/KConfigXmlParser.cpp index 97d61342..7dc1d9f0 100644 --- a/src/kconfig_compiler/KConfigXmlParser.cpp +++ b/src/kconfig_compiler/KConfigXmlParser.cpp @@ -27,7 +27,7 @@ static void preProcessDefault(QString &defaultValue, const QString &name, const QString &type, - const CfgEntry::Choices &choices, + const CfgEntry::Choices &cfgChoices, QString &code, const KConfigParameters &cfg) { @@ -51,13 +51,12 @@ static void preProcessDefault(QString &defaultValue, cpp << " QStringList default" << name << ";\n"; } const QStringList defaults = defaultValue.split(QLatin1Char(',')); - QStringList::ConstIterator it; - for (it = defaults.constBegin(); it != defaults.constEnd(); ++it) { + for (const auto &val : defaults) { cpp << " default" << name << ".append( "; if (type == QLatin1String("UrlList")) { cpp << "QUrl::fromUserInput("; } - cpp << "QString::fromUtf8( \"" << *it << "\" ) "; + cpp << "QString::fromUtf8( \"" << val << "\" ) "; if (type == QLatin1String("UrlList")) { cpp << ") "; } @@ -66,7 +65,7 @@ static void preProcessDefault(QString &defaultValue, defaultValue = QLatin1String("default") + name; } else if (type == QLatin1String("Color") && !defaultValue.isEmpty()) { - const QRegularExpression colorRe(QRegularExpression::anchoredPattern(QStringLiteral("\\d+,\\s*\\d+,\\s*\\d+(,\\s*\\d+)?"))); + static const QRegularExpression colorRe(QRegularExpression::anchoredPattern(QStringLiteral("\\d+,\\s*\\d+,\\s*\\d+(,\\s*\\d+)?"))); if (colorRe.match(defaultValue).hasMatch()) { defaultValue = QLatin1String("QColor( ") + defaultValue + QLatin1String(" )"); @@ -75,13 +74,12 @@ static void preProcessDefault(QString &defaultValue, } } else if (type == QLatin1String("Enum")) { - QList::ConstIterator it; - for (it = choices.choices.constBegin(); it != choices.choices.constEnd(); ++it) { - if ((*it).name == defaultValue) { - if (cfg.globalEnums && choices.name().isEmpty()) { - defaultValue.prepend(choices.prefix); + for (const auto &choice : cfgChoices.choices) { + if (choice.name == defaultValue) { + if (cfg.globalEnums && cfgChoices.name().isEmpty()) { + defaultValue.prepend(cfgChoices.prefix); } else { - defaultValue.prepend(enumTypeQualifier(name, choices) + choices.prefix); + defaultValue.prepend(enumTypeQualifier(name, cfgChoices) + cfgChoices.prefix); } break; } @@ -96,9 +94,8 @@ static void preProcessDefault(QString &defaultValue, cpp << " QList default" << name << ";\n"; if (!defaultValue.isEmpty()) { const QStringList defaults = defaultValue.split(QLatin1Char(',')); - QStringList::ConstIterator it; - for (it = defaults.constBegin(); it != defaults.constEnd(); ++it) { - cpp << " default" << name << ".append( " << *it << " );\n"; + for (const auto &defaultVal : defaults) { + cpp << " default" << name << ".append( " << defaultVal << " );\n"; } } defaultValue = QLatin1String("default") + name; -- cgit v1.2.1