[KListOpenFilesJob] Use QString::splitRef()
ClosedPublic

Authored by ahmadsamir on Dec 26 2019, 5:52 AM.

Details

Summary

As per apol's suggestion in D26210, use splitRef(). And Since it returns
a QVector<String>, use std::unique to remove the duplicates.

Test Plan

make && ctest

Diff Detail

Repository
R244 KCoreAddons
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
ahmadsamir created this revision.Dec 26 2019, 5:52 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptDec 26 2019, 5:52 AM
ahmadsamir requested review of this revision.Dec 26 2019, 5:52 AM
ahmadsamir planned changes to this revision.Dec 26 2019, 5:54 AM
ahmadsamir requested review of this revision.Dec 26 2019, 8:26 AM
dfaure requested changes to this revision.Dec 26 2019, 8:51 AM
dfaure added inline comments.
src/lib/util/klistopenfilesjob_unix.cpp
70

This does not work the way you think it does.

"A call to std::unique is typically followed by a call to a container's erase method, which erases the unspecified values and reduces the physical size of the container to match its new logical size."

Also, note that unlike removeDuplicates(), std::unique requires the container to be sorted (or at least the duplicates to be consecutive). But AFAICS the output of lsof is already sorted? In fact in all my tests I don't manage to see it output duplicates... Are you sure this can happen?

This revision now requires changes to proceed.Dec 26 2019, 8:51 AM
ahmadsamir planned changes to this revision.Dec 26 2019, 10:09 AM
ahmadsamir marked an inline comment as done.
ahmadsamir added inline comments.
src/lib/util/klistopenfilesjob_unix.cpp
70

Ouch, right; I should have read up fully on unique before using it (I skimmed the docs, always a stupid idea with a new tool).

removeDuplicates() was in the original code; and lsof would have duplicate pids, but I missed that the code actually uses lsof -t which is both sorted and unique.

I'll investigate some more and update the diff.

ahmadsamir updated this revision to Diff 72206.Dec 26 2019, 1:57 PM

Remove the call to std::unique:

  • It doesn't work like that
  • it's not needed as lsof -t already produces a sorted and unique list of pid's

One more thing, since this is lsof -t it's only 52 entries on my system (not +100000 of lsof), so it's not as big of an optimisation as I first thought (see D26226 for context).

dfaure requested changes to this revision.Dec 26 2019, 2:29 PM
dfaure added inline comments.
src/lib/util/klistopenfilesjob_unix.cpp
68–69

Now you can make it const and remove the qAsConst on the next line.

This revision now requires changes to proceed.Dec 26 2019, 2:29 PM
ahmadsamir updated this revision to Diff 72207.Dec 26 2019, 2:33 PM

Make it const... :/

dfaure accepted this revision.Dec 26 2019, 5:17 PM
This revision is now accepted and ready to land.Dec 26 2019, 5:17 PM
This revision was automatically updated to reflect the committed changes.

Thanks for the notice. Pushed a fix (#include <QVector>).