Optimization of mb_str_split#199
Merged
nicolas-grekas merged 1 commit intosymfony:masterfrom Nov 27, 2019
kamil-tekiela:Optimization-of-mb_str_split
Merged
Optimization of mb_str_split#199nicolas-grekas merged 1 commit intosymfony:masterfrom kamil-tekiela:Optimization-of-mb_str_split
nicolas-grekas merged 1 commit intosymfony:masterfrom
kamil-tekiela:Optimization-of-mb_str_split
Conversation
3 tasks
Contributor
|
This probably needs a test case with exactly this combo (split of 1, and 'UTF-8'encoding) |
Contributor
Author
|
The first test kind of handles this, because 1 and UTF-8 should be the default values. We could add the following test: |
Contributor
|
I'd say 👍 for a more explicit test for this case |
BackEndTea
approved these changes
Nov 11, 2019
IonBazan
approved these changes
Nov 14, 2019
|
-> https://3v4l.org/8XPK7 (preg_match_all) PS: I think for short strings it's even faster to use substr ? e.g. voku/portable-utf8@e70be38#diff-890805f35966ea20340b9076d7b47329R7212 |
Member
|
Thank you @kamil-tekiela. |
nicolas-grekas
added a commit
that referenced
this pull request
Nov 27, 2019
This PR was squashed before being merged into the 1.13-dev branch.
Discussion
----------
Optimization of mb_str_split
`mb_strlen` + `mb_substr` can be very slow for large strings. In the common case of split length 1 and charset UTF=8 we can use `preg_split` instead.
Added an early exit to the function:
if (1 === $split_length && 'UTF-8' === $encoding) {
return preg_split('//u', $string, null, PREG_SPLIT_NO_EMPTY);
}
See https://3v4l.org/U6PPf
Commits
-------
8dd88d7 Optimization of mb_str_split
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
mb_strlen+mb_substrcan be very slow for large strings. In the common case of split length 1 and charset UTF=8 we can usepreg_splitinstead.Added an early exit to the function:
See https://3v4l.org/U6PPf