Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Routing] fix perf issue when dumping large number of routes
  • Loading branch information
nicolas-grekas committed Feb 1, 2019
1 parent d44fba1 commit 1e4ee16
Showing 1 changed file with 5 additions and 4 deletions.
Expand Up @@ -159,6 +159,7 @@ private function groupStaticRoutes(RouteCollection $collection): array

foreach ($collection->all() as $name => $route) {
$compiledRoute = $route->compile();
$prefix = rtrim($compiledRoute->getStaticPrefix(), '/');
$hostRegex = $compiledRoute->getHostRegex();
$regex = $compiledRoute->getRegex();
if ($hasTrailingSlash = '/' !== $route->getPath()) {
Expand All @@ -173,17 +174,17 @@ private function groupStaticRoutes(RouteCollection $collection): array
if ($hasTrailingSlash) {
$url = substr($url, 0, -1);
}
foreach ($dynamicRegex as list($hostRx, $rx)) {
if (preg_match($rx, $url) && (!$host || !$hostRx || preg_match($hostRx, $host))) {
$dynamicRegex[] = [$hostRegex, $regex];
foreach ($dynamicRegex as list($hostRx, $rx, $p)) {
if (('' === $p || 0 === strpos($url, $p)) && preg_match($rx, $url) && (!$host || !$hostRx || preg_match($hostRx, $host))) {
$dynamicRegex[] = [$hostRegex, $regex, $prefix];
$dynamicRoutes->add($name, $route);
continue 2;
}
}

$staticRoutes[$url][$name] = [$route, $hasTrailingSlash];
} else {
$dynamicRegex[] = [$hostRegex, $regex];
$dynamicRegex[] = [$hostRegex, $regex, $prefix];
$dynamicRoutes->add($name, $route);
}
}
Expand Down

0 comments on commit 1e4ee16

Please sign in to comment.