Skip to content

[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

Merged
merged 1 commit into from
May 28, 2015

Conversation

nicolas-grekas
Copy link
Member

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #14558
License MIT
Doc PR -

@nicolas-grekas
Copy link
Member Author

@nicolas-grekas nicolas-grekas force-pushed the faster-lower branch 2 times, most recently from 99831fc to a064d81 Compare May 15, 2015 13:46
) {
return true;
}
if (--$i && ($id !== $lcId = strtolower($id))) {
Copy link
Contributor

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

@Tobion
Copy link
Contributor

Tobion commented May 17, 2015

I guess it would be good to have a test that ensures the bug explained by stof in #14558 (comment) is not triggered.

@nicolas-grekas
Copy link
Member Author

@stof @Tobion Any idea which test I should add? I'm not sure to have to right ideas for now.

@@ -76,6 +76,8 @@ class Container implements IntrospectableContainerInterface
protected $scopeStacks;
protected $loading = array();

private static $underscoreMap = array('_' => '', '.' => '_', '\\' => '_');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this is static?

Copy link
Member Author

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.

|| isset($this->services[$id])
|| isset($this->aliases[$id])
|| array_key_exists($id, $this->services)
|| method_exists($this, 'get'.strtr($id, $this->underscoreMap).'Service')
Copy link
Member

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)

@stof
Copy link
Member

stof commented May 20, 2015

@nicolas-grekas here is what the test should do:

  • define a container-scoped service
  • dump the container to PHP and continue the work with the dumped container (the bug in the previous PR does not affect the ContainerBuilder as its instantiation logic is different)
  • get it from the container (so that it is instantiated)
  • get it again from the container with a non-lowercase id, and a different casing than the previous time
  • assert that both instances are the same

You can run the test against the code of #14558 to ensure it catches the issue properly.

@nicolas-grekas
Copy link
Member Author

@stof thanks, done. I verified that the test fails on #14558 but not here.

@fabpot
Copy link
Member

fabpot commented May 27, 2015

👍

1 similar comment
@stof
Copy link
Member

stof commented May 28, 2015

👍

@fabpot
Copy link
Member

fabpot commented May 28, 2015

Thank you @nicolas-grekas.

@fabpot fabpot merged commit c27f564 into symfony:2.3 May 28, 2015
fabpot added a commit that referenced this pull request May 28, 2015
…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()
@nicolas-grekas nicolas-grekas deleted the faster-lower branch June 2, 2015 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants