Replace Q_FOREACH and foreach by the range based for statement
AbandonedPublic

Authored by ognarb on Nov 1 2018, 9:38 PM.

Details

Reviewers
None
Group Reviewers
KDE PIM
Summary

Replace each Q_FOREACH and foreach by the range based for statement from the c++ 11 standard . Shouldn't change anything performance wise. But it's now persistent across the repository.

Test Plan

Compile and run.

Diff Detail

Repository
R76 PIM: Event Views
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 4459
Build 4477: arc lint + arc unit
ognarb created this revision.Nov 1 2018, 9:38 PM
Restricted Application added a project: KDE PIM. · View Herald TranscriptNov 1 2018, 9:38 PM
Restricted Application added a subscriber: kde-pim. · View Herald Transcript
ognarb requested review of this revision.Nov 1 2018, 9:38 PM
ognarb edited the summary of this revision. (Show Details)Nov 1 2018, 9:40 PM
ognarb added a reviewer: KDE PIM.
dkurz added a subscriber: dkurz.Nov 1 2018, 9:54 PM

Replacing Q_FOREACH with range-based for actually might change performance, in case the data structure detaches. Basically, Q_FOREACH creates a const copy of the container and iterates over that, so no detaching happens.

Since you did not use a single qAsConst, you might be interested in https://www.kdab.com/goodbye-q_foreach/. OTOH, not using it is sometimes correct, e.g. if you iterate over an already const container or if you are extra careful that no detaching happens in the body (which might change in the future, though).

ognarb added a comment.Nov 1 2018, 9:59 PM

Replacing Q_FOREACH with range-based for actually might change performance, in case the data structure detaches. Basically, Q_FOREACH creates a const copy of the container and iterates over that, so no detaching happens.

Since you did not use a single qAsConst, you might be interested in https://www.kdab.com/goodbye-q_foreach/. OTOH, not using it is sometimes correct, e.g. if you iterate over an already const container or if you are extra careful that no detaching happens in the body (which might change in the future, though).

Interesting I will make change :D

ognarb abandoned this revision.Nov 2 2018, 10:47 AM

I rewrote two times this patch with each time a smaller subset of change, and i had some strange segfault. Probably because of qt Ptr.