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

Change count array comparison to empty array comparison to improve performance #43779

Closed
wants to merge 1 commit into from

Conversation

ging-dev
Copy link
Contributor

@ging-dev ging-dev commented Oct 27, 2021

Q A
Branch? 5.4
Bug fix? no
New feature? no
Deprecations? no
Tickets --
License MIT
Doc PR --

Everything is done automatically, I'm not sure it's good for readability, but I made this for someone interested in it.

-count($array) === 0;
-count($array) > 0;
-!count($array);
+$array === [];
+$array !== [];
+$array === [];

@nicolas-grekas
Copy link
Member

Can you provide a benchmark that would highlight the difference?

@ging-dev
Copy link
Contributor Author

ging-dev commented Oct 27, 2021

Can you provide a benchmark that would highlight the difference?

Damn, I don't think the endings are that bad, they really aren't worth using (or am I wrong somewhere). If my benchmarks are correct then maybe $arr === [] is not really worth using ;)
This PR is automatically generated using php rector Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector

https://3v4l.org/CRrKt

@nicolas-grekas
Copy link
Member

Thanks for the details.
I'm closing because this is indeed not worth the effort.

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

3 participants