8000 Make `\Request::get` more performant. by KorvinSzanto · Pull Request #12369 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Make \Request::get more performant. #12369

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,17 @@ public static function getHttpMethodParameterOverride()
*/
public function get($key, $default = null, $deep = false)
{
return $this->query->get($key, $this->attributes->get($key, $this->request->get($key, $default, $deep), $deep), $deep);
$result = $this->query->get($key, $this, $deep);
if ($result === $this) {
Copy link
Member

Choose a reason for hiding this comment

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

I would rather use the opposite conditions and using an early return rather than assigning $result over and over again inside conditions on it (which can be confusing when seeing a list of if ($result === $this) { conditions)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'd still need to store them to a variable, the only difference is the return would be within each conditional. I'd rather have a single return no?

$result = $this->attributes->get($key, $this, $deep);
}
if ($result === $this) {
$result = $this->request->get($key, $this, $deep);
}
if ($result === $this) {
return $default;
Copy link
Member

Choose a reason for hiding this comment

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

for the last one, you could pass the real default directly, using return $this->request->get($key, $default, $deep);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we'd still need the last if ($result === $this) { return $default; } as the previous conditionals will fall through if successful. I'd rather it stay to be more verbose.

}
return $result;
Copy link
Member

Choose a reason for hiding this comment

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

I would have written it this way:

if ($this !== $result = $this->query->get($key, $this, $deep)) {
    return $result;
}

if ($this !== $result = $this->attributes->get($key, $this, $deep)) {
    return $result;
}

if ($this !== $result = $this->request->get($key, $this, $deep)) {
    return $result;
}

return $default;

}

/**
Expand Down
0