From a75eb9c4ddb55e0e37d3f7a0cf547cdab87faf77 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Wed, 9 Oct 2002 13:37:02 +0000 Subject: Optimizations to various php string functions substr_count(), strrev(), nl2br(), php_addslashes() and php_memnstr(). --- ext/standard/php_string.h | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'ext/standard/php_string.h') diff --git a/ext/standard/php_string.h b/ext/standard/php_string.h index 4b10700762..aa240a6036 100644 --- a/ext/standard/php_string.h +++ b/ext/standard/php_string.h @@ -133,19 +133,24 @@ static inline char * php_memnstr(char *haystack, char *needle, int needle_len, char *end) { char *p = haystack; - char first = *needle; + char ne = needle[needle_len-1]; - /* 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; + if ((p = strchr(p, *needle)) && ne == p[needle_len-1]) { + if (!memcmp(needle, p, needle_len-1)) { + return p; + } + } + + if (p == NULL) { + return NULL; + } + p++; } + return NULL; } -- cgit v1.2.1