Ternary operator optimization tip
| From: | David Grudl | Date: | Sun, 14 Dec 2008 17:06:23 +0000 |
| Subject: | Ternary operator optimization tip | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-42255@lists.php.net to get a copy of this message | ||
Hello,
ternary operator is very nice syntactic sugar...
$foo = $cond ? $bar : $baz;
...but it may slows down scripts. When $bar is array or relative big string, it is better to aviod sugar and use if:
if ($cond) $foo = $bar; else $foo = $baz;
and reference counting will be used.
I don't know how difficult it is to implement, but it can be very useful speed optimization for PHP 5.3 to improve ternary operator to use reference counting.
David Grudl