[OPTIMISATION] Optimised routes loop.

This commit is contained in:
Simon Sessingø
2015-12-10 03:36:50 +01:00
parent c74d83796f
commit d36880e9a0
+9 -5
View File
@@ -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 // Loop through each route-request
$activeGroup = null; $activeGroup = null;
$routesCount = count($routes);
/* @var $route RouterEntry */ /* @var $route RouterEntry */
foreach($routes as $route) { for($i = 0; $i < $routesCount; $i++) {
$route = $routes[$i];
$route->setGroup($group); $route->setGroup($group);
@@ -68,7 +72,7 @@ class RouterBase {
$route->addSettings($settings); $route->addSettings($settings);
if(!($route instanceof RouterGroup)) { if(!($route instanceof RouterGroup)) {
if(is_array($newPrefixes) && count($newPrefixes) && $backstack) { if(is_array($newPrefixes) && count($newPrefixes) && $backStack) {
$route->setUrl( join('/', $newPrefixes) . $route->getUrl() ); $route->setUrl( join('/', $newPrefixes) . $route->getUrl() );
} }
@@ -84,11 +88,11 @@ class RouterBase {
$this->currentRoute = null; $this->currentRoute = null;
if(count($this->backstack)) { if(count($this->backstack)) {
$backstack = $this->backstack; $backStack = $this->backstack;
$this->backstack = array(); $this->backstack = array();
// Route any routes added to the backstack // Route any routes added to the backstack
$this->processRoutes($backstack, $mergedSettings, $newPrefixes, true, $activeGroup); $this->processRoutes($backStack, $mergedSettings, $newPrefixes, true, $activeGroup);
} }
} }
} }