Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38116 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 41323 invoked from network); 9 Jun 2008 13:43:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Jun 2008 13:43:18 -0000 Authentication-Results: pb1.pair.com header.from=tony@daylessday.org; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tony@daylessday.org; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain daylessday.org designates 89.208.40.236 as permitted sender) X-PHP-List-Original-Sender: tony@daylessday.org X-Host-Fingerprint: 89.208.40.236 mail.daylessday.org Linux 2.6 Received: from [89.208.40.236] ([89.208.40.236:52343] helo=daylessday.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FE/7A-21959-5733D484 for ; Mon, 09 Jun 2008 09:43:17 -0400 Received: from [192.168.3.91] (unknown [212.42.62.198]) by daylessday.org (Postfix) with ESMTP id 8458B6400E4; Mon, 9 Jun 2008 17:43:13 +0400 (MSD) Message-ID: <484D336E.1090206@daylessday.org> Date: Mon, 09 Jun 2008 17:43:10 +0400 User-Agent: Thunderbird 2.0.0.12 (X11/20080226) MIME-Version: 1.0 To: Michal Dziemianko CC: internals@lists.php.net References: <7E62CA6E-83F4-4F9C-86FB-75EBE7D489C9@gmail.com> In-Reply-To: <7E62CA6E-83F4-4F9C-86FB-75EBE7D489C9@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Algorithm Optimizations - string search From: tony@daylessday.org (Antony Dovgal) On 09.06.2008 15:39, Michal Dziemianko wrote: > Hello, > Here: http://212.85.117.53/DIFF.txt is small patch that will speed > up following functions: > strpos, > stripos, > strrpos > strripos, > and probably some others (all that use zend_memnstr/php_memnstr > function) The code below is definitely wrong. The pointers (haystack_dup & needle_dup) that were freed in the previous version are not freed anymore, but I can see that they are still allocated, so you have a memleak there. ---------------------- - efree(haystack_dup); - efree(needle_dup); - RETURN_FALSE; + /* actual search - note "p" is reused! */ + p = strrpos_reverse_kmp( p, needle_dup, needle_len, e); + + if ( p != NULL) { + /* if somethign was found - return offset wrt to haystack beginning */ + RETURN_LONG( p - haystack_dup ); + } else { + /* if nothing found - return FALSE */ + RETURN_FALSE; + } } /* }}} */ @@ -2530,11 +2550,9 @@ ---------------------- -- Wbr, Antony Dovgal