Skip to content

refactor: optimize prepQuotedPrintable() with hash lookup and int-length tracking#10344

Merged
paulbalandan merged 2 commits into
codeigniter4:developfrom
gr8man:refactor/email-prep-quoted-printable
Jun 30, 2026
Merged

refactor: optimize prepQuotedPrintable() with hash lookup and int-length tracking#10344
paulbalandan merged 2 commits into
codeigniter4:developfrom
gr8man:refactor/email-prep-quoted-printable

Conversation

@gr8man

@gr8man gr8man commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Description

Optimize prepQuotedPrintable() in system/Email/Email.php by replacing three expensive patterns in the hot loop:

  • in_array($ascii, $asciiSafeChars)isset($asciiSafeChars[$ascii]) using array_fill_keys()
  • static::strlen($temp) + static::strlen($char) → integer $tempLen variable, incremented/decremented
  • $escape . strtoupper(sprintf('%02s', dechex($ascii))) + static::strlen($char)sprintf('=%02X', $ascii) with preset $charLen = 3

Added unit tests covering safe chars, unsafe chars, trailing space/tab, =3D, soft line breaks at 76 chars, {unwrap} removal, null-byte stripping, both CRLF paths, and mixed content.

@gr8man gr8man force-pushed the refactor/email-prep-quoted-printable branch from 4f43143 to 2af2294 Compare June 28, 2026 22:31

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please restore the comments that remain relevant after the refactor, especially those explaining the {unwrap} removal, the custom-LF compatibility path, encoding of =, and the line-wrapping rules. These capture non-obvious behavior and will make our lives easier in the future.

@gr8man gr8man force-pushed the refactor/email-prep-quoted-printable branch from ce158a2 to 44ce027 Compare June 29, 2026 20:43
@gr8man gr8man requested a review from michalsn June 29, 2026 20:58

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@michalsn michalsn added the refactor Pull requests that refactor code label Jun 30, 2026
@paulbalandan paulbalandan changed the title refactor: optimize prepQuotedPrintable() with hash lookup and int-length tracking refactor: optimize prepQuotedPrintable() with hash lookup and int-length tracking Jun 30, 2026
@paulbalandan paulbalandan merged commit 9331fa8 into codeigniter4:develop Jun 30, 2026
56 checks passed
@paulbalandan

Copy link
Copy Markdown
Member

Thank you, @gr8man

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

Labels

refactor Pull requests that refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants