Re: Algorithm Optimizations - string search

From: Date: Mon, 09 Jun 2008 13:43:10 +0000
Subject: Re: Algorithm Optimizations - string search
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-38116@lists.php.net to get a copy of this message
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

« previous php.internals (#38116) next »