cvs: php4 /ext/standard php_string.h

From: Date: Sat, 21 Jul 2001 03:26:31 +0000
Subject: cvs: php4 /ext/standard php_string.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-6299@lists.php.net to get a copy of this message
sas Fri Jul 20 23:26:31 2001 EDT Modified files: /php4/ext/standard php_string.h Log: Drop memchr() in php_memnstr in favor of manual scanning. This reduces the complexity of the function and is about 20% faster on Linux/x86. Index: php4/ext/standard/php_string.h diff -u php4/ext/standard/php_string.h:1.39 php4/ext/standard/php_string.h:1.40 --- php4/ext/standard/php_string.h:1.39 Wed Jul 4 06:10:29 2001 +++ php4/ext/standard/php_string.h Fri Jul 20 23:26:31 2001 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_string.h,v 1.39 2001/07/04 10:10:29 wez Exp $ */ +/* $Id: php_string.h,v 1.40 2001/07/21 03:26:31 sas Exp $ */ /* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */ @@ -123,12 +123,18 @@ php_memnstr(char *haystack, char *needle, int needle_len, char *end) { char *p = haystack; - char *s = NULL; + char first = *needle; - for(; p <= end - needle_len && - (s = (char*)memchr(p, *needle, end - p - needle_len + 1)); p = s + 1) { - if(memcmp(s, needle, needle_len) == 0) - return s; + /* let end point to the last character where needle may start */ + end -= needle_len; + + while (p <= end) { + while (*p != first) + if (++p > end) + return NULL; + if (memcmp(p, needle, needle_len) == 0) + return p; + p++; } return NULL; }

« previous php.cvs (#6299) next »