Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ PHP 8.7 UPGRADE NOTES
. Improved performance of array_chunk() when not preserving keys.
. Improved performance of array_splice() when inserting without removing
elements.
. Improved performance of str_replace() when the search string is longer than
one byte and the replacement has a different length.
. Improved performance of str_rot13().
. Improved performance of pack() for large strings using the a, A and Z
formats.
Expand Down
13 changes: 9 additions & 4 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -3340,9 +3340,9 @@ static zend_string *php_str_to_str_ex(zend_string *haystack,
const char *o = ZSTR_VAL(haystack);
const char *n = needle;
const char *endp = o + ZSTR_LEN(haystack);
const char *first_match = php_memnstr(o, n, needle_len, endp);

while ((o = (char*)php_memnstr(o, n, needle_len, endp))) {
o += needle_len;
for (o = first_match; o; o = php_memnstr(o + needle_len, n, needle_len, endp)) {
count++;
}
if (count == 0) {
Expand All @@ -3360,10 +3360,15 @@ static zend_string *php_str_to_str_ex(zend_string *haystack,

e = ZSTR_VAL(new_str);
end = ZSTR_VAL(haystack) + ZSTR_LEN(haystack);
for (p = ZSTR_VAL(haystack); (r = (char*)php_memnstr(p, needle, needle_len, end)); p = r + needle_len) {
*replace_count += count;
p = ZSTR_VAL(haystack);
for (r = first_match; ; r = php_memnstr(p, needle, needle_len, end)) {
e = zend_mempcpy(e, p, r - p);
e = zend_mempcpy(e, str, str_len);
(*replace_count)++;
p = r + needle_len;
if (--count == 0) {
break;
}
}

if (p < end) {
Expand Down
Loading