[php-src] PR #12961: Add specialized implementation of mb_strcut for GB18030
| From: | alexdowad | Date: | Sat, 16 Dec 2023 13:10:24 +0000 |
| Subject: | [php-src] PR #12961: Add specialized implementation of mb_strcut for GB18030 | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-24528@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/12961
Author: alexdowad
For GB18030, it is not generally possible to identify character boundaries without scanning through
the entire string. Therefore, implement mb_strcut using a similar strategy as the mblen_table based
implementation in mbstring.c. The difference is that for GB18030, we need to look at two leading
bytes to determine the byte length of a multi-byte character.
The new implementation is 4-5x faster for short strings, and more than 10x faster for long strings.
(Part of the reason why this new code has such a great performance advantage is because it is
replacing code based on the older text conversion filters provided by libmbfl, which were quite
slow.)
The behavior is the same as before for valid GB18030 strings; for some invalid strings, mb_strcut
will choose different 'cut' points as compared to before. (Clang's libFuzzer was used
to compare the old and new implementations, searching for test cases where they had different
behavior; no such cases were found.)
@Girgias @cmb69 @youkidearitai @nielsdos @kamil-tekiela