Commit
substr_compare() is up to 2x slower than just substr(). Use a faster, more common, and simpler to read variant of the same thing.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -261,7 +261,10 @@ protected function _url() { | |
} | ||
$endsWithIndex = '/webroot/index.php'; | ||
$endsWithLength = strlen($endsWithIndex); | ||
if (strlen($uri) >= $endsWithLength && substr_compare($uri, $endsWithIndex, -$endsWithLength, $endsWithLength) === 0) { | ||
if ( | ||
strlen($uri) >= $endsWithLength && | ||
substr($uri, -$endsWithLength) == $endsWithIndex | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
markstory
Author
Member
|
||
) { | ||
$uri = '/'; | ||
} | ||
return $uri; | ||
|
Is this code style official CakePHP standard?
Didn't find any example here:
http://book.cakephp.org/2.0/en/contributing/cakephp-coding-conventions.html
I already encoutered this style once somewhere in the codebase, but I prefer the first expression on the same line as the if and the last expression on the line with the closing bracket.