Navigation Menu

Skip to content

Commit

Permalink
Speed up url matching for route without variable
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb authored and fabpot committed Dec 20, 2010
1 parent 98db58a commit 5e94807
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php
Expand Up @@ -60,17 +60,25 @@ protected function addMatcher()
$conditions[] = sprintf("isset(\$this->context['method']) && preg_match('#^(%s)$#xi', \$this->context['method'])", $req);
}

if ($compiledRoute->getStaticPrefix()) {
$conditions[] = sprintf("0 === strpos(\$url, '%s')", $compiledRoute->getStaticPrefix());
}
if (!count($compiledRoute->getVariables()) && false !== preg_match('#^(.)\^(?P<url>.*?)\$\1#', $compiledRoute->getRegex(), $m)) {
$conditions[] = sprintf("\$url === '%s'", $m['url']);

$matches = 'array()';
} else {
if ($compiledRoute->getStaticPrefix()) {
$conditions[] = sprintf("0 === strpos(\$url, '%s')", $compiledRoute->getStaticPrefix());
}

$conditions[] = sprintf("preg_match('%s', \$url, \$matches)", $compiledRoute->getRegex());
$conditions[] = sprintf("preg_match('%s', \$url, \$matches)", $compiledRoute->getRegex());

$matches = '$matches';
}

$conditions = implode(' && ', $conditions);

$code[] = sprintf(<<<EOF
if ($conditions) {
return array_merge(\$this->mergeDefaults(\$matches, %s), array('_route' => '%s'));
return array_merge(\$this->mergeDefaults($matches, %s), array('_route' => '%s'));
}
EOF
Expand Down
Expand Up @@ -29,6 +29,10 @@ public function match($url)
return array_merge($this->mergeDefaults($matches, array ()), array('_route' => 'bar'));
}

if ($url === '/test/baz') {
return array_merge($this->mergeDefaults(array(), array ()), array('_route' => 'baz'));
}

return false;
}
}
Expand Up @@ -38,6 +38,10 @@ public function testDump()
array(),
array('_method' => 'GET|head')
));
$collection->add('baz', new Route(
'/test/baz'
));

$dumper = new PhpMatcherDumper($collection);
$this->assertStringEqualsFile(self::$fixturesPath.'/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.');
}
Expand Down

0 comments on commit 5e94807

Please sign in to comment.