[KFileWidgets] Port QRegExp to QRegularExpression
ClosedPublic

Authored by ahmadsamir on Jan 1 2020, 10:01 AM.

Details

Summary

Optimise the code in checkPreviewInternal(): use const where possible,
and use range-for instead of iterator-based loops.

Test Plan

make && ctest

Diff Detail

Repository
R241 KIO
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.Jan 1 2020, 10:01 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptJan 1 2020, 10:01 AM
ahmadsamir requested review of this revision.Jan 1 2020, 10:01 AM
dfaure requested changes to this revision.Jan 1 2020, 10:09 AM
dfaure added inline comments.
src/filewidgets/kdiroperator.cpp
1481

const QStringList result =

rather than declaring result before the loop.

But while we're here, shouldn't we use indexOf() instead of filter()? All we care for is "there is at least one match".

1489

declare where used

1490

declare where used

(this also makes refactoring easier btw)

1504

You could combine this with the next line and kill the "match" variable. More compact and more readable IMHO.

src/filewidgets/kfilewidget.cpp
2458

declare where used

2462

(same)

This revision now requires changes to proceed.Jan 1 2020, 10:09 AM
ahmadsamir updated this revision to Diff 72522.Jan 1 2020, 12:32 PM

Address comments

ahmadsamir added inline comments.Jan 1 2020, 12:54 PM
src/filewidgets/kfilewidget.cpp
2458

Declaring rx before the for-loop isn't more efficient? then inside the for-loop it's the same QRegularExpression object and setPattern() is called.

dfaure added inline comments.Jan 1 2020, 5:36 PM
src/filewidgets/kfilewidget.cpp
2458

Hmm OK this isn't like QString, reusing rx saves allocating/deallocating its d pointer indeed.

ahmadsamir updated this revision to Diff 72564.Jan 1 2020, 7:07 PM

Declare QRegularExpression before for-loop

dfaure accepted this revision.Jan 1 2020, 7:17 PM
This revision is now accepted and ready to land.Jan 1 2020, 7:17 PM
This revision was automatically updated to reflect the committed changes.