-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Avoid unnecessary calls to strtolower() #14643
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
nicolas-grekas
commented
May 15, 2015
Q | A |
---|---|
Bug fix? | yes |
New feature? | no |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #14558 |
License | MIT |
Doc PR | - |
0f13066
to
5eb89ff
Compare
99831fc
to
a064d81
Compare
) { | ||
return true; | ||
} | ||
if (--$i && ($id !== $lcId = strtolower($id))) { |
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 brackets around $id !== $lcId = strtolower($id)
seem useless
I guess it would be good to have a test that ensures the bug explained by stof in #14558 (comment) is not triggered. |
a064d81
to
3d71aef
Compare
@@ -76,6 +76,8 @@ class Container implements IntrospectableContainerInterface | |||
protected $scopeStacks; | |||
protected $loading = array(); | |||
|
|||
private static $underscoreMap = array('_' => '', '.' => '_', '\\' => '_'); |
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.
Why this is static?
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.
It's faster and private. But I just made it non static, that won't make a significant difference.
3d71aef
to
f405c32
Compare
|| isset($this->services[$id]) | ||
|| isset($this->aliases[$id]) | ||
|| array_key_exists($id, $this->services) | ||
|| method_exists($this, 'get'.strtr($id, $this->underscoreMap).'Service') |
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 suggest checking the methodMap before doing the replacements here (as done in get
)
@nicolas-grekas here is what the test should do:
You can run the test against the code of #14558 to ensure it catches the issue properly. |
f405c32
to
c27f564
Compare
👍 |
1 similar comment
👍 |
Thank you @nicolas-grekas. |
…wer() (nicolas-grekas) This PR was merged into the 2.3 branch. Discussion ---------- [DependencyInjection] Avoid unnecessary calls to strtolower() | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #14558 | License | MIT | Doc PR | - Commits ------- c27f564 [DependencyInjection] Avoid unnecessary calls to strtolower()