btwael / mammouth

Unfancy PHP
http://mammouth.boutglay.com
MIT License
214 stars 22 forks source link

Optimize for loops #55

Closed pronebird closed 8 years ago

pronebird commented 9 years ago

The following loop is converted into a php for loop with count($projects) called on each iteration. It would be better to cache the size of array.

projects = ['mammouth', 'locallydb', 'JISON', 'CoffeeScript']
for project in projects
  echo project

So I imagine that optimal output should be:

$projects = array('mammouth', 'locallydb', 'JISON', 'CoffeeScript');
for($_i = 0, $_count = count($projects); $_i < $_count; $_i++) {
  $project = $projects[$_i];
  echo $project;
}
btwael commented 9 years ago

Awesome, thank you, that will be optimized in the third version, where I'm working now :100:

btwael commented 8 years ago

Fixed take a look