Skip to content

Remove superfluous helper variable in Randomizer::getBytes() #9563

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

Merged
merged 2 commits into from
Sep 20, 2022

Conversation

joshuaruesweg
Copy link
Member

@joshuaruesweg joshuaruesweg commented Sep 16, 2022

I am currently looking at the random extension to extend it in the future. In the process, I noticed that an auxiliary variable was introduced at this point, which is not needed in my eyes. I don't know if the compiler doesn't optimise this variable anyway, but I wanted to make the pull request anyway, because I think the code is more understandable this way.

@cmb69
Copy link
Member

cmb69 commented Sep 17, 2022

Thank you for the PR! I'd leave that as is (for better readability regarding the names and the types (unsigned vs. signed)), but leave that to @zeriyoshi and @TimWolla to decide.

@TimWolla
Copy link
Member

for better readability regarding the names and the types (unsigned vs. signed)

I agree it's a little more obvious regarding the types. I just had to look up how exactly a comparison between unsigned and signed works. However I find the use of two different variable names for the same value confusing. Especially since the trailing NUL byte is added based on length, not required_size. So that would be a “yes” from me.

Looking at the function I'd also move the declaration of result into the while() loop, as it is not used outside the loop, I've added such a commit.

I'll let zeriyoshi have the final review.

@TimWolla TimWolla requested a review from zeriyoshi September 17, 2022 13:57
Copy link
Contributor

@zeriyoshi zeriyoshi left a comment

Choose a reason for hiding this comment

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

Thanks for your help in improving it! Looks like a good change to me.

@TimWolla TimWolla merged commit ca39984 into php:PHP-8.2 Sep 20, 2022
TimWolla added a commit that referenced this pull request Sep 20, 2022
* PHP-8.2:
  Remove superfluous helper variable in `Randomizer::getBytes()` (#9563)
@joshuaruesweg joshuaruesweg deleted the randomizer-randomBytes branch September 24, 2022 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants