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

refactor: refactor bad smell ToArrayCallWithZeroLengthArrayArgument #4990

Merged

Conversation

MartinWitt
Copy link
Collaborator

Repairing Code Style Issues

ToArrayCallWithZeroLengthArrayArgument

The performance of the empty array version is the same, and sometimes even better, compared
to the pre-sized version. Also, passing a pre-sized array is dangerous for a concurrent or
synchronized collection as a data race is possible between the size and toArray
calls. This may result in extra nulls at the end of the array if the collection was concurrently
shrunk during the operation.


See https://shipilev.net/blog/2016/arrays-wisdom-ancients/ for more details.

Repairing Code Style Issues

  • ToArrayCallWithZeroLengthArrayArgument (1)

- ToArrayCallWithZeroLengthArrayArgument
The performance of the empty array version is the same, and sometimes even better, compared
to the pre-sized version. Also, passing a pre-sized array is dangerous for a concurrent or
synchronized collection as a data race is possible between the <code>size</code> and <code>toArray</code>
calls. This may result in extra <code>null</code>s at the end of the array if the collection was concurrently
shrunk during the operation.</p>
See https://shipilev.net/blog/2016/arrays-wisdom-ancients/ for more details.
@MartinWitt
Copy link
Collaborator Author

I more or less trust the analysis from IntelliJ and shipilev. I have not measured the numbers by myself.
@SirYwell ping for performance related PRs.

Copy link
Collaborator

@SirYwell SirYwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@MartinWitt MartinWitt changed the title refactor: refactor bad smell ToArrayCallWithZeroLengthArrayArgument review: refactor: refactor bad smell ToArrayCallWithZeroLengthArrayArgument Nov 2, 2022
@SirYwell SirYwell changed the title review: refactor: refactor bad smell ToArrayCallWithZeroLengthArrayArgument refactor: refactor bad smell ToArrayCallWithZeroLengthArrayArgument Nov 4, 2022
@SirYwell SirYwell merged commit 618c736 into INRIA:master Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants