mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
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.
This commit is contained in:
parent
fc260e6c98
commit
09ce807bf1
1 changed files with 11 additions and 5 deletions
|
@ -123,12 +123,18 @@ static inline char *
|
|||
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue