Skip to content

Use memchr for end-of-line scan in php_mimepart_parse#57

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:pr/parse-memchr-eol
Open

Use memchr for end-of-line scan in php_mimepart_parse#57
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:pr/parse-memchr-eol

Conversation

@iliaal
Copy link
Copy Markdown

@iliaal iliaal commented Jun 7, 2026

php_mimepart_parse scans each input chunk for the next newline to split it into lines, which is the inner loop of all message parsing. Replaced the hand-rolled byte-at-a-time scan with memchr so libc can scan a machine word at a time. Behaviour is unchanged: a chunk with a newline is appended through the \n and handed to php_mimepart_process_line; a chunk without one is buffered for the next call.

The per-chunk newline search was a hand-rolled byte-at-a-time loop.
memchr lets libc scan a word at a time, which matters because this is
the inner loop of all message parsing. Behaviour is unchanged: a chunk
with a newline is appended up to and including the '\n' and handed to
php_mimepart_process_line; a chunk without one is buffered for the next
call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant