-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Revert "minor #19689 [DI] Cleanup array_key_exists (ro0NL)" #19848
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,6 +223,7 @@ public function has($id) | |
if ('service_container' === $id | ||
|| isset($this->aliases[$id]) | ||
|| isset($this->services[$id]) | ||
|| array_key_exists($id, $this->services) | ||
) { | ||
return true; | ||
} | ||
|
@@ -265,7 +266,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE | |
$id = $this->aliases[$id]; | ||
} | ||
// Re-use shared service instance if it exists. | ||
if (isset($this->services[$id])) { | ||
if (isset($this->services[$id]) || array_key_exists($id, $this->services)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, can't the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fast path first, slow path last. isset first, array_key_exists last There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But 2 calls instead of 1 in the worst case, and a code harder to read and maintain. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when worst case means less likely case, it's on purpose |
||
return $this->services[$id]; | ||
} | ||
|
||
|
@@ -347,7 +348,7 @@ public function initialized($id) | |
$id = $this->aliases[$id]; | ||
} | ||
|
||
return isset($this->services[$id]); | ||
return isset($this->services[$id]) || array_key_exists($id, $this->services); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here. |
||
} | ||
|
||
/** | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
IIUC,
$this->services
always exist and is always an array, so this line can be removed (thearray_key_exists
call in the next will do the check).Uh oh!
There was an error while loading. Please reload this page.
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 but: isset is faster, and isset is what we'll keep on 3.x - and this is a revert, let's stop "optimizing" things that worked fine and had already been reviewed hundred of times.
Uh oh!
There was an error while loading. Please reload this page.
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.
Ok to ease the merge between branches.
Regarding the perf, does it really worth to make the code more complex for such micro-optimizations?
Uh oh!
There was an error while loading. Please reload this page.
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.
container->has/get() is full of micro-optimizations because it can be called thousands of time.
Which immediately unqualifies this as a "micro"-optimization and makes it a "macro" one.