From 3b0a3d4109dc8550603fc4412dd2ec8d7cae0d93 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 18 Dec 2010 14:36:11 -0500 Subject: [PATCH] Making route matching fail even faster. This gives significant performance boosts to routes not matching. --- cake/libs/route/cake_route.php | 4 +++- cake/tests/cases/libs/route/cake_route.test.php | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cake/libs/route/cake_route.php b/cake/libs/route/cake_route.php index 27e453ea9..bbe70bc63 100644 --- a/cake/libs/route/cake_route.php +++ b/cake/libs/route/cake_route.php @@ -265,7 +265,7 @@ class CakeRoute { //check that all the key names are in the url $keyNames = array_flip($this->keys); - if (array_intersect_key($keyNames, $url) != $keyNames) { + if (array_intersect_key($keyNames, $url) !== $keyNames) { return false; } @@ -287,6 +287,7 @@ class CakeRoute { // keys that exist in the defaults and have different values cause match failures. $keyExists = array_key_exists($key, $defaults); if ($keyExists && $defaults[$key] != $value) { + return false; $diff[$key] = $value; continue; } @@ -308,6 +309,7 @@ class CakeRoute { // keys that don't exist are different. if (!$keyExists && !empty($value)) { + return false; $diff[$key] = $value; } } diff --git a/cake/tests/cases/libs/route/cake_route.test.php b/cake/tests/cases/libs/route/cake_route.test.php index aa6a7246b..279e305f1 100644 --- a/cake/tests/cases/libs/route/cake_route.test.php +++ b/cake/tests/cases/libs/route/cake_route.test.php @@ -219,7 +219,7 @@ class CakeRouteTestCase extends CakeTestCase { * @return void **/ function testMatchBasic() { -/* $route = new CakeRoute('/:controller/:action/:id', array('plugin' => null)); + $route = new CakeRoute('/:controller/:action/:id', array('plugin' => null)); $result = $route->match(array('controller' => 'posts', 'action' => 'view', 'plugin' => null)); $this->assertFalse($result); @@ -235,7 +235,7 @@ class CakeRouteTestCase extends CakeTestCase { $result = $route->match(array('controller' => 'pages', 'action' => 'display', 'about')); $this->assertFalse($result); -*/ + $route = new CakeRoute('/pages/*', array('controller' => 'pages', 'action' => 'display')); $result = $route->match(array('controller' => 'pages', 'action' => 'display', 'home')); @@ -369,7 +369,7 @@ class CakeRouteTestCase extends CakeTestCase { * @return void */ function testNamedParamsWithNullFalse() { - $route = new CakeRoute('/:controller/:action/*', array('plugin' => null)); + $route = new CakeRoute('/:controller/:action/*'); $result = $route->match(array('controller' => 'posts', 'action' => 'index', ':page' => null, 'sort' => false)); $this->assertEquals('/posts/index/', $result); }