Permalink
Browse files

Use simpler and faster code.

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...
1 parent 521c293 commit 2f57a7fb18cbbe207dcb0f89cd6c66ab6e7e47b1 @markstory markstory committed Jul 2, 2013
Showing with 4 additions and 1 deletion.
  1. +4 โˆ’1 lib/Cake/Network/CakeRequest.php
@@ -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
@ravage84
ravage84 Jul 2, 2013 Member

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.

@markstory
markstory Jul 2, 2013 Member

I do it, because I have a tiny computer and find wrapped lines hard to read ๐Ÿ˜„. I don't think it is part of the official style rules or sniffs just something I and some other people do.

@jeremyharris
jeremyharris Jul 2, 2013 Contributor

But is it PSR-2 compatible? Much easier to read! :D

@ravage84
ravage84 Jul 2, 2013 Member

@markstory I understand from your statement that you need a new computer ;-P

@cakephp Your big honcho needs a new machine to work more efficient!

@markstory
markstory Jul 2, 2013 Member

No, I'm quite happy with the 13" monitor I have :D

@ravage84
ravage84 Jul 2, 2013 Member

Oo
Good man, seriously If I had a spare monitor and the shipping to Canada wasn't so expensive you could have it!

@markstory
markstory Jul 2, 2013 Member

It's not for a lack of funding, more that I'm often working in places where big monitors don't fit :)

@ravage84
ravage84 Jul 2, 2013 Member

I thought so ;-)

I guess you are quite wanted anyway...
How do you find the time to work, contribute to CakePHP and all thos other stuff (and last but not least your family as I have read in your blog)? Geez! grin

@jeremyharris
jeremyharris Jul 2, 2013 Contributor

@ravage84 several of us are of the thinking that he's not actually a single person but a well-trained team of 5-10 developers, where the Mark we see at conferences is the "face" of the organization. Just a theory, though.

@ravage84
ravage84 Jul 2, 2013 Member

@jeremyharris With "a well-trained team of devs" you mean poor slaves, who work all day in a dark, dusty and moisty room, right?

@jeremyharris
jeremyharris Jul 2, 2013 Contributor

@ravage84 ew, "moist"

@ravage84
ravage84 Jul 2, 2013 Member

@jeremyharris Ups, but I actually looked it up first http://www.dict.cc/?s=moisty ;-)

@dereuromark
dereuromark Jul 2, 2013 Member

"in places where big monitors don't fit" How poor must these slaves be if the master of all has already work space issues ๐Ÿก
They probably have to develop with a smartphone.

@markstory
markstory Jul 2, 2013 Member

They/I mainly work on my couch, or kitchen table.

@jeremyharris
jeremyharris Jul 2, 2013 Contributor

@ravage84 haha, figured it was a language thing ;) A lot of people (at least near me) hear the word "moist" and cringe

@markstory hah! At long last my theories have been confirmed. Tell real Mark good job and I'll stop making so much noise on GH :)

+ ) {
$uri = '/';
}
return $uri;

0 comments on commit 2f57a7f

Please sign in to comment.