Skip to content

Commit a2ea452

Browse files
committed
Return early from mb_get_substr if 'len' parameter is zero
This internal function is used to implement mb_strstr, mb_stristr, mb_strrchr, mb_strrichr, mb_substr, mb_strimwidth, mb_trim, and mb_str_pad. All of these functions will be faster if we return early when requested for a zero-length "substring".
1 parent 56077b0 commit a2ea452

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

ext/mbstring/mbstring.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,7 @@ static zend_string* mb_get_substr(zend_string *input, size_t from, size_t len, c
21082108
unsigned char *in = (unsigned char*)ZSTR_VAL(input);
21092109
size_t in_len = ZSTR_LEN(input);
21102110

2111-
if (from >= in_len) {
2111+
if (from >= in_len || len == 0) {
21122112
/* No supported text encoding decodes to more than one codepoint per byte
21132113
* So if the number of codepoints to skip >= number of input bytes,
21142114
* then definitely the output should be empty */

0 commit comments

Comments
 (0)