summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorSascha Schumann <sas@php.net>2001-07-21 03:26:31 +0000
committerSascha Schumann <sas@php.net>2001-07-21 03:26:31 +0000
commit09ce807bf1f97c13faa735b2712251902f42b18e (patch)
tree3587f1ee2bef92f08d768deea14735357e49a90f /ext
parentfc260e6c98e69800051d6a7c48cfba186da76ea8 (diff)
downloadphp-git-09ce807bf1f97c13faa735b2712251902f42b18e.tar.gz
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.
Diffstat (limited to 'ext')
-rw-r--r--ext/standard/php_string.h18
1 files changed, 12 insertions, 6 deletions
diff --git a/ext/standard/php_string.h b/ext/standard/php_string.h
index 7e0ea30dcb..7143ccf3be 100644
--- a/ext/standard/php_string.h
+++ b/ext/standard/php_string.h
@@ -123,12 +123,18 @@ static inline char *
php_memnstr(char *haystack, char *needle, int needle_len, char *end)
{
char *p = haystack;
- char *s = NULL;
-
- 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;
+ char first = *needle;
+
+ /* 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;
}