Skip to content

ext/standard: Optimize single-character searches in strcspn() and strpbrk() - #24087

Merged
LamentXU123 merged 1 commit into
php:masterfrom
LamentXU123:20261003opt
Oct 3, 2026
Merged

LamentXU123 merged 1 commit into
php:masterfrom
LamentXU123:20261003opt

Conversation

@LamentXU123

@LamentXU123 LamentXU123 commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

When I was optimizing str_repeat last month there is a logic inside it:

php-src/ext/standard/string.c

Lines 5648 to 5651 in fab508f

/* Heavy optimization for situations where input string is 1 byte long */
if (ZSTR_LEN(input_str) == 1) {
memset(ZSTR_VAL(result), *ZSTR_VAL(input_str), mult);
} else {

Today when reading this piece of code I realize same stuff can be applied on these two functions.

@LamentXU123
LamentXU123 merged commit c33572a into php:master Oct 3, 2026
18 checks passed
@LamentXU123

Copy link
Copy Markdown
Member Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants