D9205: QStringList initializer list cleanup
Milian Wolff
noreply at phabricator.kde.org
Tue Dec 5 15:22:04 UTC 2017
mwolff added a comment.
better than before, but some things could be improved some more
INLINE COMMENTS
> katedocument.cpp:4518
> + // view variable names
> + static const QStringList vvl {
> + QStringLiteral("dynamic-word-wrap")
even better would be to not name this list type at all, to use initializer_list and then use STL algorithms on it, but this is already better. The advantage of my suggested pattern is that there is no memory allocation at all anymore.
Compare https://godbolt.org/g/3SvKNw against https://godbolt.org/g/w9ySts (it should be similar for QStrings)
> katedocument.cpp:4613
> else if (var == QLatin1String("eol") || var == QLatin1String("end-of-line")) {
> - QStringList l;
> - l << QStringLiteral("unix") << QStringLiteral("dos") << QStringLiteral("mac");
> + const QStringList l{ QStringLiteral("unix"), QStringLiteral("dos"), QStringLiteral("mac") };
> if ((n = l.indexOf(val.toLower())) != -1) {
dito
> katedocument.cpp:4733
> val = val.trimmed().toLower();
> - static const QStringList trueValues = QStringList() << QStringLiteral("1") << QStringLiteral("on") << QStringLiteral("true");
> + static const QStringList trueValues{ QStringLiteral("1"), QStringLiteral("on"), QStringLiteral("true") };
> if (trueValues.contains(val)) {
dito
> katedocument.cpp:4739
>
> - static const QStringList falseValues = QStringList() << QStringLiteral("0") << QStringLiteral("off") << QStringLiteral("false");
> + static const QStringList falseValues{ QStringLiteral("0"), QStringLiteral("off"), QStringLiteral("false") };
> if (falseValues.contains(val)) {
dito
> katescriptmanager.cpp:119
> */
> - foreach (const QString &type, QStringList() << QLatin1String("indentation") << QLatin1String("commands")) {
> + for (const QString type : { QLatin1String("indentation"), QLatin1String("commands") }) {
> // basedir for filesystem lookup
use auto on the left
> kateview.cpp:1385
>
> - QStringList l;
> -
> - l << QStringLiteral("edit_replace")
> - << QStringLiteral("tools_spelling")
> - << QStringLiteral("tools_indent")
> - << QStringLiteral("tools_unindent")
> - << QStringLiteral("tools_cleanIndent")
> - << QStringLiteral("tools_align")
> - << QStringLiteral("tools_comment")
> - << QStringLiteral("tools_uncomment")
> - << QStringLiteral("tools_toggle_comment")
> - << QStringLiteral("tools_uppercase")
> - << QStringLiteral("tools_lowercase")
> - << QStringLiteral("tools_capitalize")
> - << QStringLiteral("tools_join_lines")
> - << QStringLiteral("tools_apply_wordwrap")
> - << QStringLiteral("tools_spelling_from_cursor")
> - << QStringLiteral("tools_spelling_selection");
> + static const QStringList l {
> + QStringLiteral("edit_replace")
don't name a type (use initializer list) and then use range-based for below
REPOSITORY
R39 KTextEditor
REVISION DETAIL
https://phabricator.kde.org/D9205
To: dhaumann, mwolff
Cc: #frameworks, kevinapavew, ngraham, demsking, cullmann, sars, dhaumann
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20171205/baa55d4a/attachment-0001.html>
More information about the Kde-frameworks-devel
mailing list