Repository navigation
Conversation
|
//cc @SanderMuller |
SanderMuller
left a comment
There was a problem hiding this comment.
Both replacements give the same result as the old regexes. I compared them on 201,025 strings: every byte value alone, doubled and next to a letter, and random strings of up to 10 characters. The random strings used digits, the 4 wildcard characters, \xB2, an Arabic-Indic digit and NUL. There was no difference, also with the UTF-8 ctype locale that the CLI sets.
On the PR head, FileExcluderTest, the trim tests in NodeScopeResolverTest, phpcs and make phpstan pass. The 3 red integration jobs are also red on #7007. Mutation Testing (8.4) did not run, because the download of infection got a 504 Gateway Time-out.
The run-time effect is very small. Self-analysis reaches the changed checks 1,591 times. With the largest difference in your tables (about 22 ns), that is less than 0.1 ms per run.
A separate problem that is older than this PR: trim() accepts a range like '/..:', which includes all digits without a digit character. So for a numeric-string $s, PHPStan types trim($s, '/..:') as numeric-string, but trim('12', '/..:') is ''. The old regex has the same gap. I can open an issue for it.
yes, please open a issue |
|
Opened phpstan/phpstan#15683. I also found that |
inspired by PHP-CS-Fixer/PHP-CS-Fixer#9924
benchmark
strpbrk()withtrim/preg_match():