Re: Re: Ternary operator performance improvements
| From: | Ivan Enderlin @ Hoa | Date: | Wed, 09 Nov 2011 13:52:11 +0000 |
| Subject: | Re: Re: Ternary operator performance improvements | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-56191@lists.php.net to get a copy of this message | ||
Hi Miroslav & Arnaud,
On 09/11/11 12:51, Miroslav Kubelík wrote:
On 10/14/2011 10:08 PM, Arnaud Le Blanc wrote:Best regards. -- Ivan Enderlin Developer of Hoa http://hoa.42/ or http://hoa-project.net/ PhD. student at LIFC/DISC (Vesontio) and INRIA (Cassis) http://lifc.univ-fcomte.fr/ and http://www.inria.fr/ Member of HTML and WebApps Working Group of W3C http://w3.org/Hi, I've already posted this patch and it has since been reviewed and improved. I'm re-posting it for discussion before eventually commiting it. The ternary operator always copies its second or third operand, which is very slow compared to an if/else when the operand is an array for example: ...Same "copy always" behavior is made with string in ternary operator, and it can be also very annoying e.g: $content = file_get_contents('http://www.w3.org/TR/2011/WD-html-markup-20110525/spec.html'); $test = $content !== false ? $content : ''; Is it the same with: $content = file_get_contents('…') ?: ''; Maybe we could have a heuristic for this shortcut operator no?