Skip to content

Commit

Permalink
Use simpler and faster code.
Browse files Browse the repository at this point in the history
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
markstory committed Jul 2, 2013
1 parent 521c293 commit 2f57a7f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/Cake/Network/CakeRequest.php
Expand Up @@ -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.

Copy link
@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.

This comment has been minimized.

Copy link
@markstory

markstory Jul 2, 2013

Author 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.

This comment has been minimized.

Copy link
@jeremyharris

jeremyharris Jul 2, 2013

Member

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

This comment has been minimized.

Copy link
@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!

This comment has been minimized.

Copy link
@markstory

markstory Jul 2, 2013

Author Member

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

This comment has been minimized.

Copy link
@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!

This comment has been minimized.

Copy link
@markstory

markstory Jul 2, 2013

Author Member

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

This comment has been minimized.

Copy link
@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

This comment has been minimized.

Copy link
@jeremyharris

jeremyharris Jul 2, 2013

Member

@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.

This comment has been minimized.

Copy link
@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?

This comment has been minimized.

Copy link
@jeremyharris

jeremyharris Jul 2, 2013

Member

@ravage84 ew, "moist"

This comment has been minimized.

Copy link
@ravage84

ravage84 Jul 2, 2013

Member

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

This comment has been minimized.

Copy link
@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.

This comment has been minimized.

Copy link
@markstory

markstory Jul 2, 2013

Author Member

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

This comment has been minimized.

Copy link
@jeremyharris

jeremyharris Jul 2, 2013

Member

@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;
Expand Down

0 comments on commit 2f57a7f

Please sign in to comment.