Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:26961 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94941 invoked by uid 1010); 14 Dec 2006 20:23:35 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 94926 invoked from network); 14 Dec 2006 20:23:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Dec 2006 20:23:35 -0000 X-Host-Fingerprint: 83.160.219.156 korving.demon.nl Received: from [83.160.219.156] ([83.160.219.156:29743] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7D/62-14414-4A2B1854 for ; Thu, 14 Dec 2006 15:23:35 -0500 Message-ID: <7D.62.14414.4A2B1854@pb1.pair.com> To: internals@lists.php.net References: <10.23.32177.CA640854@pb1.pair.com> <00e501c71fa4$5bdee3a0$0100a8c0@pc07653> Date: Thu, 14 Dec 2006 21:21:52 +0100 Lines: 134 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Posted-By: 83.160.219.156 Subject: Re: [PHP-DEV] [PATCH] 1 small optimization and 1 cleanup From: r.korving@xit.nl ("Ron Korving") If you have good reason to believe it will be slower, then naturaly we should forget about that patch. I don't know much about cache hitrates. The other patch removes bogus code, which should be good I reckon. If you still want the patch for PCRE though, a patch with braces follows below. - Ron ### Eclipse Workspace Patch 1.0 #P php5 Index: ext/pcre/php_pcre.c =================================================================== RCS file: /repository/php-src/ext/pcre/php_pcre.c,v retrieving revision 1.209 diff -u -r1.209 php_pcre.c --- ext/pcre/php_pcre.c 10 Oct 2006 12:43:34 -0000 1.209 +++ ext/pcre/php_pcre.c 14 Dec 2006 20:19:38 -0000 @@ -417,18 +417,35 @@ PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *preg_options, int *compile_options TSRMLS_DC) { pcre_cache_entry * pce = pcre_get_compiled_regex_cache(regex, strlen(regex) TSRMLS_CC); - - if (extra) { - *extra = pce ? pce->extra : NULL; - } - if (preg_options) { - *preg_options = pce ? pce->preg_options : 0; + + if (pce) + { + if (extra) { + *extra = pce->extra; + } + if (preg_options) { + *preg_options = pce->preg_options; + } + if (compile_options) { + *compile_options = pce->compile_options; + } + + return pce->re; } - if (compile_options) { - *compile_options = pce ? pce->compile_options : 0; + else + { + if (extra) { + *extra = NULL; + } + if (preg_options) { + *preg_options = 0; + } + if (compile_options) { + *compile_options = 0; + } + + return NULL; } - - return pce ? pce->re : NULL; } /* }}} */ ""Nuno Lopes"" wrote in message news:00e501c71fa4$5bdee3a0$0100a8c0@pc07653... > > Hi, > > > > Below are 2 patches for the latest 5.2. The first patch rewrites > > pcre_get_compiled_regex_ex() in ext/pcre/php_pcre.c from line 417, saving > > up > > to 3 comparison statements (?:). The second patch removes a pointless > > statement (setting a local variable right before a return statement) from > > json_determine_array_type() in ext/json/json.c on line 92. > > well about the pcre one I could argument that your patch makes the code > bigger and potentially slower :P (due to cache misses) Anyway, I do trust > the compiler to do such kind of trivial optimizations.. > > > > Index: ext/pcre/php_pcre.c > > =================================================================== > > RCS file: /repository/php-src/ext/pcre/php_pcre.c,v > > retrieving revision 1.209 > > diff -u -r1.209 php_pcre.c > > --- ext/pcre/php_pcre.c 10 Oct 2006 12:43:34 -0000 1.209 > > +++ ext/pcre/php_pcre.c 13 Dec 2006 18:22:07 -0000 > > @@ -417,18 +417,21 @@ > > PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, > > int *preg_options, int *compile_options TSRMLS_DC) > > { > > pcre_cache_entry * pce = pcre_get_compiled_regex_cache(regex, > > strlen(regex) TSRMLS_CC); > > - > > - if (extra) { > > - *extra = pce ? pce->extra : NULL; > > - } > > - if (preg_options) { > > - *preg_options = pce ? pce->preg_options : 0; > > + > > + if (pce) > > + { > > + if (extra) *extra = pce->extra; > > + if (preg_options) *preg_options = pce->preg_options; > > + if (compile_options) *compile_options = pce->compile_options; > > + return pce->re; > > } > > - if (compile_options) { > > - *compile_options = pce ? pce->compile_options : 0; > > + else > > + { > > + if (extra) *extra = NULL; > > + if (preg_options) *preg_options = 0; > > + if (compile_options) *compile_options = 0; > > + return NULL; > > } > > - > > - return pce ? pce->re : NULL; > > } > > /* }}} */