-
-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reorder ByteSequence constants #364
Conversation
@@ -17,27 +17,27 @@ | |||
interface ByteSequence | |||
{ | |||
/** | |||
* UTF-8 BOM sequence. | |||
* UTF-32 BE BOM sequence. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the re-ordering is not the issue, the issue is in the implementation of bom_match
the function should be updated by sorting the constant using their value length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I too thought relying on a definition order in the interface was flaky but it was the path of least resistance. And, the test would guard it from becoming out of order in the future.
@jmwebservices thanks for the PR. This is a good start but to resolve the issue, the <?php
function bom_match(string $str): string
{
static $list;
if (null === $list) {
$list = (new ReflectionClass(ByteSequence::class))->getConstants();
rsort($list, SORT_NATURAL | SORT_FLAG_CASE);
}
foreach ($list as $sequence) {
if (0 === strpos($str, $sequence)) {
return $sequence;
}
}
return '';
} I have no tested the result but this is the way to go, Changing the order in the interface makes it part of a specific implementation and that defeat the purpose of an interface. |
Would you be interested in the following?
|
1/ the reflection magic is done for maintenance and speed:
So I would be against changing this part of the code. 2/ some tests should be conducted or some literature (with a link) should be provided to see if If the full length is still computed then I see no gain in doing so |
I am getting crazy performance improvements. On my machine, using https://gist.github.com/jmwebservices/3cd9cb273ec52f835a6dd13d62b2bc76 |
This optimization may be unccessary since a quick search over the code base indicates that Line 228 in 42c8916
|
@jmwebservices are you gonna modify the function or not else I can take over your PR and merge the changes so I can release before the end of the year 🤔🤔😉 |
I was waiting on your reply on my last comment about whether the optimization is needed at all. But yes, please go ahead and modify to address the bug. The end of year has me swamped. Thanks for your contribution! |
@jmwebservices sorry I thought by your last answer that you were not going to add the optimization since its useless in the CSV codebase 😢 . I'll still mention your contribution in the changelog don't worry about that 😉 |
this merge is closed and I'll be using #365 instead |
Fix for #363