Skip to content
Merged
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 @@ -86,6 +86,8 @@ PHP 8.7 UPGRADE NOTES
========================================

- Standard:
. Improved performance of strcspn() and strpbrk() when searching longer strings
with a single-byte character mask.
. Improved performance of array_splice() when inserting without removing
elements.
. Improved performance of str_rot13().
Expand Down
5 changes: 5 additions & 0 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,11 @@ static size_t php_strspn_strcspn_common(const char *haystack, const char *charac
* We only compare in this case.
* Empirically tested that the table lookup approach is only beneficial if characters is longer than 1 character. */
if (characters_end - characters == 1) {
/* Avoid memchr() overhead for short spans and an immediate match. */
if (!must_match && haystack_end - haystack >= 16 && *haystack != *characters) {
const char *ptr = memchr(haystack, (unsigned char) *characters, haystack_end - haystack);
return ptr ? (size_t) (ptr - haystack) : (size_t) (haystack_end - haystack);
}
const char *ptr = haystack;
while (ptr < haystack_end && (*ptr == *characters) == must_match) {
ptr++;
Expand Down
Loading