Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:32357 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56015 invoked by uid 1010); 17 Sep 2007 11:10:23 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 56000 invoked from network); 17 Sep 2007 11:10:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Sep 2007 11:10:23 -0000 Authentication-Results: pb1.pair.com smtp.mail=nlopess@php.net; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=nlopess@php.net; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 212.55.154.21 as permitted sender) X-PHP-List-Original-Sender: nlopess@php.net X-Host-Fingerprint: 212.55.154.21 relay1.ptmail.sapo.pt Linux 2.4/2.6 Received: from [212.55.154.21] ([212.55.154.21:50567] helo=sapo.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BD/46-22480-E906EE64 for ; Mon, 17 Sep 2007 07:10:23 -0400 Received: (qmail 1517 invoked from network); 17 Sep 2007 11:10:18 -0000 Received: from unknown (HELO sapo.pt) (10.134.35.209) by relay1 with SMTP; 17 Sep 2007 11:10:18 -0000 Received: (qmail 12913 invoked from network); 17 Sep 2007 11:10:15 -0000 X-AntiVirus: PTMail-AV 0.3-0.91.1 X-Virus-Status: Clean (0.01909 seconds) Received: from unknown (HELO pc07653) (nunoplopes@sapo.pt@[82.155.78.179]) (envelope-sender ) by mta14 (qmail-ldap-1.03) with SMTP for ; 17 Sep 2007 11:10:15 -0000 Message-ID: <000701c7f91b$55fb3c30$4001a8c0@pc07653> To: =?iso-8859-1?Q?Johannes_Schl=FCter?= Cc: "Peter Brodersen" , References: <001f01c7f6f0$dbcf5350$4001a8c0@pc07653> <002201c7f894$1b236060$4001a8c0@pc07653> <1189983923.17667.24.camel@johannes.nop> Date: Mon, 17 Sep 2007 12:10:20 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138 Subject: Re: [PHP-DEV] Re: RFC: mark functions as const for possibleoptimizations From: nlopess@php.net ("Nuno Lopes") > On Sun, 2007-09-16 at 20:02 +0100, Nuno Lopes wrote: >> > >My proposal is the following: >> > >some functions when fed with constant arguments always return a >> > >constant >> > >value, too. e.g.: >> > >strlen('abcd') === 4. >> > >> > I like the general idea. >> > >> > Would there be some caveats with stuff like this if it is possible to >> > change the charset at runtime? >> > >> > I guess it is important to be aware of whether a function is affected >> > by different settings (and if these settings can be changed at >> > runtime) to conclude if a function really is deterministic at this >> > level. >> >> uhm, damn, right. strlen() wasn't a good example.. my bad, sorry :S >> Anyway, you got the idea :) > > Nothing wrong with strlen as far as I can tell: > > - In PHP 5 we only have binary strings so strlen() works independent > from any charsets and encodings by just counting bytes. > - In PHP 6 we know - assuming the parameter is a constant string - the > encoding at compile time, therefore it could be used. > > The only edge-case I see is if somebody uses mbstring.func_overload and > overwrites strlen() exactly. I was thinking in mbstring, too. As long as there is some run-time setting that can affect a function, we cannot replace its call blindly with its value. Then only a more intelligent optimizer can do inference on the code and figure out if it's safe or not to replace the function call. My proposal was to mark functions susceptible of that "blind" replacement only. Nuno