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

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
gr8manforce-pushed the refactor/email-prep-quoted-printable branch from 4f43143 to 2af2294CompareJune 28, 2026 22:31

@michalsnmichalsn 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
gr8manforce-pushed the refactor/email-prep-quoted-printable branch from ce158a2 to 44ce027CompareJune 29, 2026 20:43
@gr8man
gr8man requested a review from michalsnJune 29, 2026 20:58

@michalsnmichalsn 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!

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

Copy link
Copy Markdown
Member

Thank you, @gr8man

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

Labels

refactorPull requests that refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@gr8man@paulbalandan@michalsn