summaryrefslogtreecommitdiff
path: root/ext/mbstring/mbstring.c
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2017-07-26 22:13:20 +0200
committerNikita Popov <nikita.ppv@gmail.com>2017-07-28 12:32:50 +0200
commitf56b0afe6eb3ec0dd6ec5ee6ec5cee429e41c7e5 (patch)
treed0d353cdd7a51a883b81c517dabb34c40e3d83d8 /ext/mbstring/mbstring.c
parenteacd70f762eee90ebcc2b207cd91c49d23cafc1b (diff)
downloadphp-git-f56b0afe6eb3ec0dd6ec5ee6ec5cee429e41c7e5.tar.gz
Avoid some unnecessary mbfl_strlen() calculations
Diffstat (limited to 'ext/mbstring/mbstring.c')
-rw-r--r--ext/mbstring/mbstring.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c
index cb5fb053ea..0672412789 100644
--- a/ext/mbstring/mbstring.c
+++ b/ext/mbstring/mbstring.c
@@ -2372,7 +2372,7 @@ PHP_FUNCTION(mb_strlen)
PHP_FUNCTION(mb_strpos)
{
int reverse = 0;
- zend_long offset = 0, slen;
+ zend_long offset = 0;
mbfl_string haystack, needle;
char *enc_name = NULL;
size_t enc_name_len, n;
@@ -2390,14 +2390,17 @@ PHP_FUNCTION(mb_strpos)
RETURN_FALSE;
}
- slen = mbfl_strlen(&haystack);
- if (offset < 0) {
- offset += slen;
- }
- if (offset < 0 || offset > slen) {
- php_error_docref(NULL, E_WARNING, "Offset not contained in string");
- RETURN_FALSE;
+ if (offset != 0) {
+ size_t slen = mbfl_strlen(&haystack);
+ if (offset < 0) {
+ offset += slen;
+ }
+ if (offset < 0 || offset > slen) {
+ php_error_docref(NULL, E_WARNING, "Offset not contained in string");
+ RETURN_FALSE;
+ }
}
+
if (needle.len == 0) {
php_error_docref(NULL, E_WARNING, "Empty delimiter");
RETURN_FALSE;
@@ -2494,7 +2497,7 @@ PHP_FUNCTION(mb_strrpos)
}
}
- {
+ if (offset != 0) {
size_t haystack_char_len = mbfl_strlen(&haystack);
if ((offset > 0 && offset > haystack_char_len) ||
(offset < 0 && -offset > haystack_char_len)) {
@@ -5399,7 +5402,7 @@ MBSTRING_API size_t php_mb_stripos(int mode, const char *old_haystack, size_t ol
break;
}
- {
+ if (offset != 0) {
size_t haystack_char_len = mbfl_strlen(&haystack);
if (mode) {