D12233: Avoid manipulation of lists with quadratic complexity

Michael Heidelbach noreply at phabricator.kde.org
Mon Apr 16 13:42:22 UTC 2018


michaelh added inline comments.

INLINE COMMENTS

> bruns wrote in fileindexscheduler.cpp:148
> 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);
>                              });

I suppose developers on my level will appreciate code to be most self-explanatory. I'm not objecting though, we might al well go "all the way":

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

> bruns wrote in pendingfilequeue.cpp:66
> 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.

Ooops.

REPOSITORY
  R293 Baloo

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

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


More information about the Kde-frameworks-devel mailing list