New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilize ++iter rather than iter++ to improve iterator performance. #1353

Merged
merged 1 commit into from Jul 16, 2015

Conversation

Projects
None yet
3 participants
@Areloch
Contributor

Areloch commented Jul 14, 2015

Issue found with PVS-Studio:

Many places utilize post-incrementation with iterators, but it's better performance to use pre-incrementation.

Resolved by changing the iter++ instances to ++iter;

Issue found with PVS-Studio:
Many places utilize post-incrementation with iterators, but it's better performance to use pre-incrementation.

Resolved by changing the iter++ instances to ++iter;

@Areloch Areloch added this to the 3.8 milestone Jul 14, 2015

@crabmusket

This comment has been minimized.

Show comment
Hide comment
@crabmusket

crabmusket Jul 14, 2015

Contributor

I am so saddened that the compiler cannot optimise this. Just sad.

Contributor

crabmusket commented Jul 14, 2015

I am so saddened that the compiler cannot optimise this. Just sad.

@crabmusket crabmusket added the Defect label Jul 14, 2015

@andr3wmac

This comment has been minimized.

Show comment
Hide comment
@andr3wmac

andr3wmac Jul 14, 2015

Contributor

@eightyeight : What makes you think the compiler won't optimize it? A lot of these corrections are a) don't rely on the compiler to optimize it for you and b) it does no harm, so may as well correct it to shut PVS Studio up.

Since the return value of the increment isn't utilized the compiler should change them to pre-increment.

Contributor

andr3wmac commented Jul 14, 2015

@eightyeight : What makes you think the compiler won't optimize it? A lot of these corrections are a) don't rely on the compiler to optimize it for you and b) it does no harm, so may as well correct it to shut PVS Studio up.

Since the return value of the increment isn't utilized the compiler should change them to pre-increment.

@Areloch

This comment has been minimized.

Show comment
Hide comment
@Areloch

Areloch Jul 14, 2015

Contributor

Yeah, quite a few issues PVS notes are things that are probably correctly handled by the compiler, but are not explicit and therefore there is room for the compiler to handle it poorly.

Changes like this, or moving away from c-style casting tell the compiler exactly what's intended, and ensures the outcome. So it's more about consistently ensuring the desired outcome, than "the compiler never gets this right".

Even so, generally good practices to do, so hey ;)

Contributor

Areloch commented Jul 14, 2015

Yeah, quite a few issues PVS notes are things that are probably correctly handled by the compiler, but are not explicit and therefore there is room for the compiler to handle it poorly.

Changes like this, or moving away from c-style casting tell the compiler exactly what's intended, and ensures the outcome. So it's more about consistently ensuring the desired outcome, than "the compiler never gets this right".

Even so, generally good practices to do, so hey ;)

@crabmusket

This comment has been minimized.

Show comment
Hide comment
@crabmusket

crabmusket Jul 14, 2015

Contributor

@andr3wmac whoops, you're right, these should be optimised by the compiler as they're primitive types. Whenever I've seen a question on this subject, the advice has always been 'use pre increment anyway', which translates in my head as 'post increment will not optimise' 😕

But yeah, I'm not disagreeing with this change.

Contributor

crabmusket commented Jul 14, 2015

@andr3wmac whoops, you're right, these should be optimised by the compiler as they're primitive types. Whenever I've seen a question on this subject, the advice has always been 'use pre increment anyway', which translates in my head as 'post increment will not optimise' 😕

But yeah, I'm not disagreeing with this change.

crabmusket added a commit that referenced this pull request Jul 16, 2015

Merge pull request #1353 from Areloch/PVS_Cleanup_803
Utilize ++iter rather than iter++ to improve iterator performance.

@crabmusket crabmusket merged commit a051fbe into GarageGames:development Jul 16, 2015

@Areloch Areloch deleted the Areloch:PVS_Cleanup_803 branch Jun 23, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment