8000 [Routing] fix perf issue when dumping large number of routes · symfony/symfony@872efe5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 872efe5

Browse files
[Routing] fix perf issue when dumping large number of routes
1 parent d44fba1 commit 872efe5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ private function groupStaticRoutes(RouteCollection $collection): array
159159

160160
foreach ($collection->all() as $name => $route) {
161161
$compiledRoute = $route->compile();
162+
$staticPrefix = rtrim($compiledRoute->getStaticPrefix(), '/');
162163
$hostRegex = $compiledRoute->getHostRegex();
163164
$regex = $compiledRoute->getRegex();
164165
if ($hasTrailingSlash = '/' !== $route->getPath()) {
@@ -173,17 +174,17 @@ private function groupStaticRoutes(RouteCollection $collection): array
173174
if ($hasTrailingSlash) {
174175
$url = substr($url, 0, -1);
175176
}
176-
foreach ($dynamicRegex as list($hostRx, $rx)) {
177-
if (preg_match($rx, $url) && (!$host || !$hostRx || preg_match($hostRx, $host))) {
178-
$dynamicRegex[] = [$hostRegex, $regex];
177+
foreach ($dynamicRegex as list($hostRx, $rx, $prefix)) {
178+
if (('' === $prefix || 0 === strpos($url, $prefix)) && preg_match($rx, $url) && (!$host || !$hostRx || preg_match($hostRx, $host))) {
179+
$dynamicRegex[] = [$hostRegex, $regex, $staticPrefix];
179180
$dynamicRoutes->add($name, $route);
180181
continue 2;
181182
}
182183
}
183184

184185
$staticRoutes[$url][$name] = [$route, $hasTrailingSlash];
185186
} else {
186-
$dynamicRegex[] = [$hostRegex, $regex];
187+
$dynamicRegex[] = [$hostRegex, $regex, $staticPrefix];
187188
$dynamicRoutes->add($name, $route);
188189
}
189190
}

0 commit comments

Comments
 (0)
0