summaryrefslogtreecommitdiff
path: root/ext/standard/php_string.h
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/php_string.h')
-rw-r--r--ext/standard/php_string.h21
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;
}