Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:42255 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54646 invoked from network); 14 Dec 2008 17:07:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Dec 2008 17:07:23 -0000 Authentication-Results: pb1.pair.com header.from=david@grudl.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=david@grudl.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain grudl.com from 209.85.134.191 cause and error) X-PHP-List-Original-Sender: david@grudl.com X-Host-Fingerprint: 209.85.134.191 mu-out-0910.google.com Received: from [209.85.134.191] ([209.85.134.191:54261] helo=mu-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DD/D5-16810-84D35494 for ; Sun, 14 Dec 2008 12:07:22 -0500 Received: by mu-out-0910.google.com with SMTP id i2so1258663mue.3 for ; Sun, 14 Dec 2008 09:07:18 -0800 (PST) Received: by 10.103.222.1 with SMTP id z1mr2621392muq.51.1229274438252; Sun, 14 Dec 2008 09:07:18 -0800 (PST) Received: from ?192.168.1.53? ([77.240.188.66]) by mx.google.com with ESMTPS id w5sm3923082mue.55.2008.12.14.09.07.16 (version=SSLv3 cipher=RC4-MD5); Sun, 14 Dec 2008 09:07:17 -0800 (PST) Message-ID: <49453D0F.6030405@grudl.com> Date: Sun, 14 Dec 2008 18:06:23 +0100 User-Agent: Thunderbird 2.0.0.18 (Windows/20081105) MIME-Version: 1.0 To: PHP internals Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit Subject: Ternary operator optimization tip From: david@grudl.com (David Grudl) 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