Re: RFC: mark functions as const for possible optimizations
| From: | Andrew Brampton | Date: | Mon, 17 Sep 2007 12:21:41 +0000 |
| Subject: | Re: RFC: mark functions as const for possible optimizations | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-32358@lists.php.net to get a copy of this message | ||
From: "Nuno Lopes" <nlopess@php.net>
To: "PHPdev" <internals@lists.php.net>
Cc: <stas@zend.com>; <andi@php.net>; <dmitry@php.net>
My proposal is the following: some functions when fed with constant arguments always return a constant value, too. e.g.: strlen('abcd') === 4. This means that an optimizer can and should do this transformation. (and others like: $a='abcd'; strlen($a); -> 4). I think Ilia created a list of such functions in his optimizer. But I would like to have that list in the core, so that everybody can benefit from it. Basically the only thing needed to do is to change PHP_FE() to PHP_CONST_FE() in the function entry tables.I had a quick question about this. When would strlen('abcd') be execuated? Say I had the code: $a = false; // This set by external input if ( $a ) $b = strlen('abcd'); Would the optimizer work out the length before the program starts to run? Or would the optimizer wait until it knows the strlen is going to be called then convert it to the constant 4? I could see the optimizer "constifying" many function calls which will never get called. thanks Andrew