-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Postpone native guessers instantiation in MimeTypeGuesser. #27323
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
Conversation
*/ | ||
private function getGuessers() | ||
{ | ||
if (!$this->nativeGuessersLoaded) { |
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.
No need for new variable, just use: if (!$this->guessers) {}
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.
This is not going to work in case someone registers new guessers later with register()
. Then native guessers will never be appended and that might affect the guessing process since there will be no default guessers.
if (!$this->nativeGuessersLoaded) { | ||
// register all natively provided mime type guessers. | ||
|
||
if (FileinfoMimeTypeGuesser::isSupported()) { |
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.
Just asking: couldn't we detect if native guessers are available during the application compilation with a compiler pass?
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.
Yes, I understand what you are proposing. Yes, this can be done once while compilation. But then it's better not to use a Singleton and have just a normal ChainGuesser, empty by default. The problem is that MimeTypeGuesser
as a Singleton is already used everywhere, so it's easier to fix it this way.
Status: Needs Review |
This is a new feature (or put another way, this is not a bug fix), so it must be on the master branch. |
Agree. I will rebase it at the end of the week. |
// register all natively provided mime type guessers. | ||
|
||
if (FileinfoMimeTypeGuesser::isSupported()) { | ||
$this->guessers[] = new FileinfoMimeTypeGuesser(); |
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.
this changes the existing behavior, as they are now registered at the end while the existing logic registers them before custom ones.
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.
In existing code native guessers are prepended to an empty array in a private constructor. By the time guess
is called, native loaders are always at the end of the array.
In this PR they are added later. So to have the same behavior, I add them to the end of the array in a reversed order.
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.
ah, I forgot the fact that register
was prepending the guessers
Status: Needs Review |
Oops I'm sorry I missed this PR and made #27359 instead. Thank you @vudaltsov for working on this anyway! |
In this PR I made singleton
MimeTypeGuesser
lazy. Now it registersFileinfoMimeTypeGuesser
andFileBinaryMimeTypeGuesser
only whenguess()
is called. Should improve performance.I don't think it's a feature - more a fix... Can this be merged into 2.7?