The changes are simple. They are supposed to improve phpbb's performance without changing its functionality.
No1:
Instead of using:
Code: Select all
if (sizeof($some_array))
Code: Select all
if (empty($some_array))
Some small tests using 2 while loops (one for each one of this situations) and 5000 cycles shows that:
0.21661281585693
vs
0.055058002471924
And a test without while loop show (this is the most favorable result to sizeof):
9.9897384643555E-5
vs
2.8133392333984E-5 <- May I say... This number is very stable between tests.
No2.
Code: Select all
if (strpos($string, '?') === 0)
Use:
Code: Select all
if ($string[0] === '?')
Some small tests using 2 while loops (one for each one of this situations) and 5000 cycles shows that:
0.30220890045166
vs
0.12246012687683
And a test without while loop show (this is the most favorable result to strpos):
8.0108642578125E-5
vs
2.6941299438477E-5 <- May I say... This number is very stable between tests.
These two tests show that what I'm suggesting is a faster way of executing the code than the way it appears in many places in the current phpbb's source code.
The changes I'm requesting is based on these sentences:
- sizeof() is a function used to check the size of an array or a string, it's not supposed to be used to check if an array has elements. There are better ways of doing that at the moment.
E.g.
These are wrong:
Code: Select all
if (sizeof($array))
if (sizeof($array) > 0)
Code: Select all
if (!empty($array))
Code: Select all
if (sizeof($array) > 1)
Code: Select all
if (sizeof($array) > 30)
These are all wrong:
If you know the string has, at least, 1 character
Code: Select all
if (strpos($string, '!') === 0)
if (strpos($string, 'g') === 0)
Code: Select all
if (strpos($string, '6') === 5)
if (strpos($string, 'j') === 5)
Code: Select all
if (strpos($string, 'abc') === 0)
if (strpos($string, 'atl') === 3)
If you know the string has, at least, 1 character
Code: Select all
if ($string[0] === '!')
if ($string[0] === 'g')
Code: Select all
if ($string[5] === '6')
if ($string[5] === 'j')
What do you say about this? Comments are welcome (well... this is an RFC, anyway)!
Edit: After some attention calls, I made some extra stuff.