From d36880e9a03ade6f00d8dd90c933c4068420b425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Thu, 10 Dec 2015 03:36:50 +0100 Subject: [PATCH] [OPTIMISATION] Optimised routes loop. --- src/Pecee/SimpleRouter/RouterBase.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Pecee/SimpleRouter/RouterBase.php b/src/Pecee/SimpleRouter/RouterBase.php index be513d3..0e94242 100644 --- a/src/Pecee/SimpleRouter/RouterBase.php +++ b/src/Pecee/SimpleRouter/RouterBase.php @@ -38,13 +38,17 @@ class RouterBase { } } - protected function processRoutes(array $routes, array $settings = array(), array $prefixes = array(), $backstack = false, $group = null) { + protected function processRoutes(array $routes, array $settings = array(), array $prefixes = array(), $backStack = false, $group = null) { // Loop through each route-request $activeGroup = null; + $routesCount = count($routes); + /* @var $route RouterEntry */ - foreach($routes as $route) { + for($i = 0; $i < $routesCount; $i++) { + + $route = $routes[$i]; $route->setGroup($group); @@ -68,7 +72,7 @@ class RouterBase { $route->addSettings($settings); if(!($route instanceof RouterGroup)) { - if(is_array($newPrefixes) && count($newPrefixes) && $backstack) { + if(is_array($newPrefixes) && count($newPrefixes) && $backStack) { $route->setUrl( join('/', $newPrefixes) . $route->getUrl() ); } @@ -84,11 +88,11 @@ class RouterBase { $this->currentRoute = null; if(count($this->backstack)) { - $backstack = $this->backstack; + $backStack = $this->backstack; $this->backstack = array(); // Route any routes added to the backstack - $this->processRoutes($backstack, $mergedSettings, $newPrefixes, true, $activeGroup); + $this->processRoutes($backStack, $mergedSettings, $newPrefixes, true, $activeGroup); } } }