diff options
author | Ilia Alshanetsky <iliaa@php.net> | 2002-10-09 13:37:02 +0000 |
---|---|---|
committer | Ilia Alshanetsky <iliaa@php.net> | 2002-10-09 13:37:02 +0000 |
commit | a75eb9c4ddb55e0e37d3f7a0cf547cdab87faf77 (patch) | |
tree | 684642a841bcfb6287cbf69669478b4ba3fad044 /ext/standard/php_string.h | |
parent | 40d1127568fc6d0b0789a5c26b835a8884587112 (diff) | |
download | php-git-a75eb9c4ddb55e0e37d3f7a0cf547cdab87faf77.tar.gz |
Optimizations to various php string functions substr_count(), strrev(),
nl2br(), php_addslashes() and php_memnstr().
Diffstat (limited to 'ext/standard/php_string.h')
-rw-r--r-- | ext/standard/php_string.h | 21 |
1 files changed, 13 insertions, 8 deletions
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; } |