-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Removed unnecessary $tokenCount var #8080
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
Conversation
|
Using |
|
@arrilot No. |
|
So out of curiosity - I was wondering how much effect using For a 100,000 array:
So it is an order of magnitude faster to precalculate the array size. However that is only for an extremely large array. Arrays less than 1,000 had no noticeable runtime difference. Note - I dont support or deny the PR one way or the other - was just curious and thought I'd post my results here "for science" |
|
👎 |
|
@phanan, unfortunately, you are not correct. |
|
@GrahamCampbell No worries, I've been wrong numerous times in my life 😄 But which statement of mine is incorrect this time? @theshiftexchange and @arrilot According to the for loop documentation:
Which means the call to <?php
function called() {
echo 'Called';
return 10;
}
for ($i = 0, $j = called(); $i < $j; ++$i) {
echo $i;
}
// output: Called0123456789 |
|
Ohhh, @phanan you are actually correct. I apologise. I misread the diff as having the function call after the semicolon, rather than before it, in the bit where we initialise the iteration. |
|
@theshiftexchange No, this isn't executed every time. If it were, then |
|
Yep - in my test I didnt do the var initizilation the way @phanan did it. His way is correct and produces same run times for the array |
|
Even then, this change is totally pointless. We could put every single variable in that bit of the for statement if we wanted to, but why would we? The current way is actually more readable. |
|
And the performance is identical. |
|
You say "removed", but actually, you've basically just renamed it, and moved it a little bit lower in the code... |
|
@GrahamCampbell Agreed. I tend to be too nitpicking time to time... |
I know @taylorotwell said he tends to "shy away" from these "cleanup PRs," but can't help it.