10 Apr
2007
10 Apr
'07
8:20 a.m.
On Tuesday, 10. April 2007, Karoly Negyesi wrote:
Hi,
Note my trick in http://drupal.org/node/134697 which shows that the hash lookups in Zend Engine are a bit faster than branching.
Instead of
$class = $class == 'even' ? 'odd' : 'even'
we have
$flip = array('even' => 'odd', 'odd' => 'even'); $class = $flip[$class];
Just out of interest, what's with if ($class !== 'even') { $class = 'odd'; } ? Wouldn't this avoid half the assignments and replace the other half with a simple check (while making the code still a bit more readable)? Maybe there's some optimization magic that I don't know of, though. Regards, Jakob