You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Optimize mb_check_encoding (cut execution time by 50%+)
Previously, mb_check_encoding did an awful lot of unneeded work. In order to determine
whether a string was valid or not, it would convert the whole string into wchar (code
points), which required dynamically allocating a (potentially large) buffer. Then it
would turn right around and convert that big 'ol buffer of code points back to the
original encoding again. Finally, it would check whether any invalid bytes were
detected during that long and onerous process.
The thing is, mbstring _already_ has machinery for detecting whether a string is
valid in a certain encoding or not, and it doesn't require copying any data around
or allocating buffers. Better yet, it can fail fast when an invalid byte is found.
Why not use it? It's sure a lot faster!
0 commit comments