Count poll and run with potentially one less branch #1525
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: The same condition can be expressed with a single statement.
n += (~n > 0);
or
n += (~n != 0);
However this introduces an additional
~
operation for every loop.An equivalent but more convoluted loop counts down:
Ultimately, each method should be checking the non-zero flag, so outside additional few nanoseconds worth of instructions they should be equivalent, main point is to remove an unnecessary branch. I've only modified the related the windows file as an example, and I'm not sure where the other implementation exists.