[OPTIMISATION] Optimised more foreach loops to improve performance.

This commit is contained in:
Simon Sessingø
2015-12-10 03:41:10 +01:00
parent d36880e9a0
commit 3ba2cec8af
3 changed files with 24 additions and 7 deletions
+15 -3
View File
@@ -112,8 +112,13 @@ class RouterBase {
$routeNotAllowed = false;
$max = count($this->controllerUrlMap);
/* @var $route RouterEntry */
foreach($this->controllerUrlMap as $route) {
for($i = 0; $i < $max; $i++) {
$route = $this->controllerUrlMap[$i];
$routeMatch = $route->matchRoute($this->request);
if($routeMatch && !($routeMatch instanceof RouterGroup)) {
@@ -270,8 +275,12 @@ class RouterBase {
$c = '';
$method = null;
$max = count($this->controllerUrlMap);
/* @var $route RouterRoute */
foreach($this->controllerUrlMap as $route) {
for($i = 0; $i < $max; $i++) {
$route = $this->controllerUrlMap[$i];
// Check an alias exist, if the matches - use it
if($route instanceof RouterRoute && strtolower($route->getAlias()) === strtolower($controller)) {
@@ -292,7 +301,10 @@ class RouterBase {
$c = '';
// No match has yet been found, let's try to guess what url that should be returned
foreach($this->controllerUrlMap as $route) {
for($i = 0; $i < $max; $i++) {
$route = $this->controllerUrlMap[$i];
if($route instanceof RouterRoute && !is_callable($route->getCallback()) && stripos($route->getCallback(), '@') !== false) {
$c = $route->getClass();
} else if($route instanceof RouterController || $route instanceof RouterResource) {
+5 -2
View File
@@ -301,8 +301,11 @@ abstract class RouterEntry {
if(preg_match('/^'.$regex.'$/is', $url, $parameterValues)) {
$parameters = array();
if(count($parameterNames)) {
foreach($parameterNames as $name) {
$max = count($parameterNames);
if(count($max)) {
for($i = 0; $i < $max; $i++) {
$name = $parameterNames[$i];
$parameterValue = (isset($parameterValues[$name['name']]) && !empty($parameterValues[$name['name']])) ? $parameterValues[$name['name']] : null;
if($name['required'] && $parameterValue === null) {
+4 -2
View File
@@ -72,8 +72,10 @@ class RouterRoute extends RouterEntry {
$parameters = $matches[1];
}
if(count($parameters)) {
foreach($parameters as $param) {
$max = count($parameters);
if($max) {
for($i = 0; $i < $max; $i++) {
$param = $parameters[$i];
$this->parameters[$param] = '';
}
}