diff options
| author | Ahmad Samir <a.samirh78@gmail.com> | 2021-02-23 00:37:11 +0200 | 
|---|---|---|
| committer | Ahmad Samir <a.samirh78@gmail.com> | 2021-03-06 01:35:08 +0200 | 
| commit | 9d87348260316af729892c58bc29f159a173abf1 (patch) | |
| tree | af81edda4bf441239f4ccc66dbfb533c5be26a47 /src/kconfig_compiler | |
| parent | ee35bdce8f6b08922b4c9e0c0c838e5f2c4a79ad (diff) | |
| download | kconfig-9d87348260316af729892c58bc29f159a173abf1.tar.gz kconfig-9d87348260316af729892c58bc29f159a173abf1.tar.bz2 | |
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
Diffstat (limited to 'src/kconfig_compiler')
| -rw-r--r-- | src/kconfig_compiler/KConfigHeaderGenerator.cpp | 6 | ||||
| -rw-r--r-- | src/kconfig_compiler/KConfigSourceGenerator.cpp | 9 | ||||
| -rw-r--r-- | src/kconfig_compiler/KConfigXmlParser.cpp | 25 | 
3 files changed, 20 insertions, 20 deletions
| diff --git a/src/kconfig_compiler/KConfigHeaderGenerator.cpp b/src/kconfig_compiler/KConfigHeaderGenerator.cpp index 21eb51a5..08d383d8 100644 --- a/src/kconfig_compiler/KConfigHeaderGenerator.cpp +++ b/src/kconfig_compiler/KConfigHeaderGenerator.cpp @@ -254,8 +254,10 @@ void KConfigHeaderGenerator::createSignals()              stream() << whitespace() << "*/\n";          }          stream() << whitespace() << "void " << signal.name << "("; -        QList<Param>::ConstIterator it, itEnd = signal.arguments.constEnd(); -        for (it = signal.arguments.constBegin(); it != itEnd;) { + +        auto it = signal.arguments.cbegin(); +        const auto itEnd = signal.arguments.cend(); +        while (it != itEnd) {              Param argument = *it;              QString type = param(argument.type);              if (cfg().useEnumTypes && argument.type == QLatin1String("Enum")) { diff --git a/src/kconfig_compiler/KConfigSourceGenerator.cpp b/src/kconfig_compiler/KConfigSourceGenerator.cpp index ce6378cd..d308ffcd 100644 --- a/src/kconfig_compiler/KConfigSourceGenerator.cpp +++ b/src/kconfig_compiler/KConfigSourceGenerator.cpp @@ -214,8 +214,8 @@ void KConfigSourceGenerator::createConstructorParameterList()          stream() << (parseResult.parameters.isEmpty() ? "" : ",");      } -    for (QList<Param>::ConstIterator it = parseResult.parameters.constBegin(); it != parseResult.parameters.constEnd(); ++it) { -        if (it != parseResult.parameters.constBegin()) { +    for (auto it = parseResult.parameters.cbegin(); it != parseResult.parameters.cend(); ++it) { +        if (it != parseResult.parameters.cbegin()) {              stream() << ",";          }          stream() << " " << param((*it).type) << " " << (*it).name; @@ -634,8 +634,9 @@ void KConfigSourceGenerator::createNonModifyingSignalsHelper()          stream() << "  if ( " << varPath(QStringLiteral("settingsChanged"), cfg()) << " & " << signalEnumName(signal.name) << " )\n";          stream() << "    Q_EMIT " << signal.name << "("; -        QList<Param>::ConstIterator it, itEnd = signal.arguments.constEnd(); -        for (it = signal.arguments.constBegin(); it != itEnd;) { +        auto it = signal.arguments.cbegin(); +        const auto itEnd = signal.arguments.cend(); +        while (it != itEnd) {              Param argument = *it;              bool cast = false;              if (cfg().useEnumTypes && argument.type == QLatin1String("Enum")) { 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<CfgEntry::Choice>::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<int> 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; | 
