D9211: Iterate over initializer_lists to avoid mem allocs

Milian Wolff noreply at phabricator.kde.org
Thu Dec 21 23:29:51 UTC 2017


mwolff added a comment.


  much better, but can be somewhat better still.
  
  if people don't know the STL, they should learn it.

INLINE COMMENTS

> katedocument.cpp:109
> +    auto it = std::find(list.begin(), list.end(), entry);
> +    return it == list.end() ? -1 : std::distance(it, list.end());
> +}

you want to return `std::distance(list.begin(), it)` here

> katedocument.cpp:4526
> +    static const auto vvl = {
>            QStringLiteral("dynamic-word-wrap")
>          , QStringLiteral("dynamic-word-wrap-indicators")

here and below, these could now contain QLatin1String, reducing the size of the binary a bit

> katedocument.cpp:4561
>          if (onlyViewAndRenderer) {
> -            if (vvl.contains(var)) {   // FIXME define above
> +            if (indexOf(var, vvl) >= 0) {   // FIXME define above
>                  setViewVariable(var, val);

add a contains that does this check, also use it below

> katedocument.cpp:4655
>              // VIEW SETTINGS
> -            else if (vvl.contains(var)) {
> +            else if (indexOf(var, vvl) >= 0) {
>                  setViewVariable(var, val);

contains

> katedocument.cpp:4740
>      val = val.trimmed().toLower();
> -    static const QStringList trueValues{ QStringLiteral("1"), QStringLiteral("on"), QStringLiteral("true") };
> -    if (trueValues.contains(val)) {
> +    static const auto trueValues{ QStringLiteral("1"), QStringLiteral("on"), QStringLiteral("true") };
> +    if (indexOf(val, trueValues) >= 0) {

QLatin1String

> katedocument.cpp:4741
> +    static const auto trueValues{ QStringLiteral("1"), QStringLiteral("on"), QStringLiteral("true") };
> +    if (indexOf(val, trueValues) >= 0) {
>          *result = true;

contains

> katedocument.cpp:4746
>  
> -    static const QStringList falseValues{ QStringLiteral("0"), QStringLiteral("off"), QStringLiteral("false") };
> -    if (falseValues.contains(val)) {
> +    static const auto falseValues{ QStringLiteral("0"), QStringLiteral("off"), QStringLiteral("false") };
> +    if (indexOf(val, falseValues) >= 0) {

QLatin1String

> katedocument.cpp:4747
> +    static const auto falseValues{ QStringLiteral("0"), QStringLiteral("off"), QStringLiteral("false") };
> +    if (indexOf(val, falseValues) >= 0) {
>          *result = false;

contains

REPOSITORY
  R39 KTextEditor

BRANCH
  AvoidAllocs (branched from master)

REVISION DETAIL
  https://phabricator.kde.org/D9211

To: dhaumann, mwolff, apol
Cc: ngraham, #frameworks, kevinapavew, demsking, cullmann, sars, dhaumann
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20171221/3dd16698/attachment-0001.html>


More information about the Kde-frameworks-devel mailing list