Skip to content

Conversation

RytoEX
Copy link
Member

@RytoEX RytoEX commented Oct 3, 2023

Description

Qt has been porting uses of Q_FOREACH/foreach to C++11's ranged-for. Let's do the same.

References:

Motivation and Context

We target C++17. Q_FOREACH was previously suggested to be deprecated/replaced for Qt 6. While that did not happen, Qt's efforts to replace Q_FOREACH/foreach indicate that its days may be numbered.

How Has This Been Tested?

Built and ran OBS on Windows 11. Invoked the Reset Stats hotkey a few times.

Types of changes

  • Code cleanup (non-breaking change which makes code smaller or more readable)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

@RytoEX RytoEX added the Code Cleanup Non-breaking change which makes code smaller or more readable label Oct 3, 2023
@RytoEX RytoEX requested review from derrod and gxalpha October 3, 2023 17:51
@RytoEX RytoEX self-assigned this Oct 3, 2023
Copy link
Member

@gxalpha gxalpha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change.
Personally I’d at curly braces to the for-loop.

@derrod
Copy link
Member

derrod commented Oct 3, 2023

Might as well skip the variable assignment and go straight for

	for (OBSBasicStats *s : findChildren<OBSBasicStats *>())
		s->Reset();

But they're functionally equivalent.

Qt has been porting uses of Q_FOREACH/foreach to C++11's ranged-for.
Let's do the same.

References:
 * https://doc.qt.io/qt-6/foreach-keyword.html
 * https://codereview.qt-project.org/q/Q_FOREACH
@RytoEX RytoEX force-pushed the remove-qt-foreach branch from 5f04468 to 96f8b6a Compare October 4, 2023 21:33
@RytoEX
Copy link
Member Author

RytoEX commented Oct 4, 2023

I added the curly braces for the for loop (I usually prefer this anyway), but left in the variable assignment. While the assembly in Visual Studio seemed basically identical in Debug, removing the assignment produced about twice as much assembly in RelWithDebInfo. If there's an optimization to be made here by removing the assignment, maybe someone can revisit that in the future. For now, let's just let the compilers do their own thing

@RytoEX RytoEX added this to the OBS Studio 30.0 milestone Oct 4, 2023
@RytoEX RytoEX merged commit 3d05d68 into obsproject:master Oct 4, 2023
@RytoEX RytoEX deleted the remove-qt-foreach branch October 4, 2023 21:58
@gxalpha gxalpha mentioned this pull request Aug 31, 2025
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Cleanup Non-breaking change which makes code smaller or more readable hacktoberfest-accepted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants