D12233: Avoid manipulation of lists with quadratic complexity

Stefan BrĂ¼ns noreply at phabricator.kde.org
Sun Apr 15 21:27:29 UTC 2018


bruns added inline comments.

INLINE COMMENTS

> fileindexscheduler.cpp:148
> +        return file.startsWith(dir);
> +    };
> +

You can put the lambda into the `remove_if` invocation:

  auto tail = std::remove_if(list.begin(), list.end(),
                             [&dir](const QString& file) {
                                 return file.startsWith(dir);
                             });

> fileindexscheduler.cpp:150
> +
> +    auto it = std::remove_if(list.begin(), list.end(), isDescendant);
> +    list.erase(it, list.end());

`tail` instead of `it` ?

> pendingfilequeue.cpp:66
> +        auto it = std::remove_if(m_cache.begin(), m_cache.end(), isDescendant);
> +        m_cache.erase(it, m_cache.end());
>      }

You are missing the `m_pendingFiles.remove(...)` and `m_recentlyEmitted.remove(...)` calls here.

Variant A:
You can use `std::partition` instead of `std::remove_if` here (which keeps the elements between tail and .end() intact), and iterate over the tail to remove the elements from m_pendingFiles and m_recentlyEmitted. Last, do the erase(tail, m_cache.end()).

Variant B:
Use `std::remove_if`, but call `m_pendingFiles.remove()` (dito m_recentlyEmitted) inside the lambda.

Variant A is definitely the much cleaner approach.

REPOSITORY
  R293 Baloo

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

To: michaelh, #baloo
Cc: bruns, #frameworks, ashaposhnikov, michaelh, astippich, spoorun, ngraham, alexeymin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20180415/524f7dae/attachment.html>


More information about the Kde-frameworks-devel mailing list