summaryrefslogtreecommitdiff
path: root/Zend/zend_operators.h
diff options
context:
space:
mode:
authorXinchen Hui <laruence@php.net>2015-01-12 15:34:46 +0800
committerXinchen Hui <laruence@php.net>2015-01-12 15:34:46 +0800
commit31817447cc06093368f022086340ad3f6f616528 (patch)
tree474f31b74ac74a7b0a8f110331bcfa21d2187b5b /Zend/zend_operators.h
parentd805fa0d812f38878298e37caf1d6d20b6b00927 (diff)
downloadphp-git-31817447cc06093368f022086340ad3f6f616528.tar.gz
Faster zend_memnstr for long text
Diffstat (limited to 'Zend/zend_operators.h')
-rw-r--r--Zend/zend_operators.h28
1 files changed, 17 insertions, 11 deletions
diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h
index 58c5958859..ccbadc6f23 100644
--- a/Zend/zend_operators.h
+++ b/Zend/zend_operators.h
@@ -87,6 +87,8 @@ ZEND_API zend_bool instanceof_function(const zend_class_entry *instance_ce, cons
*/
ZEND_API zend_uchar _is_numeric_string_ex(const char *str, size_t length, zend_long *lval, double *dval, int allow_errors, int *oflow_info);
+ZEND_API const char* zend_memnstr_ex(const char *haystack, const char *needle, size_t needle_len, char *end);
+
END_EXTERN_C()
#if SIZEOF_ZEND_LONG == 4
@@ -181,23 +183,27 @@ zend_memnstr(const char *haystack, const char *needle, size_t needle_len, char *
return NULL;
}
- end -= needle_len;
+ if (EXPECTED(off_s < 1024 || needle_len < 3)) {
+ end -= needle_len;
- while (p <= end) {
- if ((p = (char *)memchr(p, *needle, (end-p+1))) && ne == p[needle_len-1]) {
- if (!memcmp(needle, p, needle_len-1)) {
- return p;
+ while (p <= end) {
+ if ((p = (char *)memchr(p, *needle, (end-p+1))) && ne == p[needle_len-1]) {
+ if (!memcmp(needle, p, needle_len-1)) {
+ return p;
+ }
+ }
+
+ if (p == NULL) {
+ return NULL;
}
- }
- if (p == NULL) {
- return NULL;
+ p++;
}
- p++;
+ return NULL;
+ } else {
+ return zend_memnstr_ex(haystack, needle, needle_len, end);
}
-
- return NULL;
}
static zend_always_inline const void *zend_memrchr(const void *s, int c, size_t n)