-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Routing] Optimised dumped router matcher, prevent unneeded function calls. #21755
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 1 commit
ea8c55a
0d69cfe
0425f33
56f2323
ef6ad3a
44271e0
e4a9e1e
2e180c6
9d92c57
f56cf9a
bb68154
4ab821b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…mparison.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,7 +108,12 @@ public function match(\$pathinfo) | |
\$trimmedPathinfo = rtrim(\$pathinfo, '/'); | ||
\$context = \$this->context; | ||
\$request = \$this->request; | ||
\$requestMethod = \$context->getMethod(); | ||
\$requestMethod = \$isLikeGetMethod = \$context->getMethod(); | ||
|
||
if (\$requestMethod === 'HEAD') { | ||
\$isLikeGetMethod = 'GET'; | ||
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. 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. The We had some discussions about what a "safe method" is in HTTP, but the section 9.1.1 of RFC 2616 mentions Or at least, rename 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. Actually, we don't want a boolean, because then we can't perform a meaningful optimisation. We just want to have a interpreted method, which we can check against. Otherwise we'd need to do more check than less. 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. What about renaming it to 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. I like 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. +1 for 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. I've renamed the variable to |
||
} | ||
|
||
|
||
$code | ||
|
||
|
@@ -219,11 +224,6 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren | |
$hostMatches = false; | ||
$methods = $route->getMethods(); | ||
|
||
// GET and HEAD are equivalent | ||
if (in_array('GET', $methods) && !in_array('HEAD', $methods)) { | ||
$methods[] = 'HEAD'; | ||
} | ||
|
||
$supportsTrailingSlash = $supportsRedirections && (!$methods || in_array('HEAD', $methods)); | ||
$regex = $compiledRoute->getRegex(); | ||
|
||
|
@@ -265,20 +265,40 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren | |
EOF; | ||
|
||
$gotoname = 'not_'.preg_replace('/[^A-Za-z0-9_]/', '', $name); | ||
|
||
if ($methods) { | ||
if (1 === count($methods)) { | ||
$code .= <<<EOF | ||
if (\$requestMethod != '$methods[0]') { | ||
if ($methods[0] === 'HEAD') { | ||
$code .= <<<EOF | ||
if (\$requestMethod != 'HEAD') { | ||
\$allow[] = 'HEAD'; | ||
goto $gotoname; | ||
} | ||
|
||
|
||
EOF; | ||
} else { | ||
$code .= <<<EOF | ||
if (\$isLikeGetMethod != '$methods[0]') { | ||
\$allow[] = '$methods[0]'; | ||
goto $gotoname; | ||
} | ||
|
||
|
||
EOF; | ||
} | ||
} else { | ||
$methodVariable = 'requestMethod'; | ||
|
||
if (in_array('GET', $methods)) { | ||
// Since we treat HEAD requests like GET requests we don't need to match it. | ||
$methodVariable = 'isLikeGetMethod'; | ||
$methods = array_filter($methods, function ($method) { return $method != 'HEAD'; }); | ||
} | ||
|
||
$methods = implode("', '", $methods); | ||
$code .= <<<EOF | ||
if (!in_array(\$requestMethod, array('$methods'))) { | ||
if (!in_array(\$$methodVariable, array('$methods'))) { | ||
\$allow = array_merge(\$allow, array('$methods')); | ||
goto $gotoname; | ||
} | ||
|
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.
'HEAD' ===
😉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.
Fixed, thanks!