Skip to content
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

[7.x] 3.5x faster micro performance enhancement for data_get() #32192

Merged
merged 5 commits into from
Apr 3, 2020
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Illuminate/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ function data_get($target, $key, $default = null)

$key = is_array($key) ? $key : explode('.', $key);

while (! is_null($segment = array_shift($key))) {
foreach ($key as $i => $segment) {
unset($key[$i]);

if ($segment === null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

there was a PR awhile ago that switched $var === null to is_null($var).

https://github.com/laravel/framework/pull/15655/files

Might want to switch this line to maintain consistency.

Copy link
Contributor Author

@kevindees kevindees Apr 2, 2020

Choose a reason for hiding this comment

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

This PR is in feature parity with the current 7.x state.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree the behavior is the same, but to maintain style consistency, we should switch $segment === null to is_null($segment).

Also, FYI. Parity, not parody.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return $target;
}

if ($segment === '*') {
if ($target instanceof Collection) {
$target = $target->all();
Expand Down