Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use (int) instead of intval() for performance reasons and to unify it. #4570

Merged
merged 3 commits into from
Sep 10, 2014

Conversation

dereuromark
Copy link
Member

Micro-optimization (no its not nano^^) of int/float casting.
(int) is about 3 times faster than the method call. Same for (float).

And we already mainly use (int), (float) casts etc where applicable.

I used my auto-correct Cast sniff

cake CodeSniffer.CodeSniffer run --sniffs MyCakePHP.PHP.Cast {corefolder} -v -f

That means, we could make this a CakePHP code-sniffer rule to keep the improvement in the future.

It should be noted that I skipped on non-trivial replacements (more than a single argument) for now due to probably errors then (intval($x + $y) would need to keep the parentheses). It would be easy to keep the additional (superfluous) parentheses, if no-one minds though. That would probably eliminate the change of errors.

// Inspired by this and this.

@markstory markstory added this to the 3.0.0 milestone Sep 10, 2014
@markstory
Copy link
Member

Looks good to me.

@dereuromark
Copy link
Member Author

Actually, I was able to refine the sniffer rules. It now is aware of operations in between and will keep the parentheses then, otherwise it will remove them. This makes it possible to use this sniffer as a whole now.

markstory added a commit that referenced this pull request Sep 10, 2014
Use (int) instead of intval() for performance reasons and to unify it.
@markstory markstory merged commit 282bc0c into master Sep 10, 2014
@markstory markstory deleted the master-casting branch September 10, 2014 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants