Skip to content

Performance Enhancement: Call toArray with Zero Array Size#65

Closed
DaGeRe wants to merge 1 commit into
apache:masterfrom
DaGeRe:master
Closed

Performance Enhancement: Call toArray with Zero Array Size#65
DaGeRe wants to merge 1 commit into
apache:masterfrom
DaGeRe:master

Conversation

@DaGeRe

@DaGeRe DaGeRe commented Oct 10, 2018

Copy link
Copy Markdown
Contributor

toArray should, at least since Java 7, be used with new T[0] instead of size, since it is "faster, safer, and contractually cleaner" (https://shipilev.net/blog/2016/arrays-wisdom-ancients/#_conclusion)

@kinow

kinow commented Feb 16, 2019

Copy link
Copy Markdown
Member

Hi @DaGeRe ! I don't know if anything changed in Java 10+, but I think this is a good change, and will mark it as approved. Alas I can't merge it straight away due to the failing Travis-CI builds. I am not certain that they are related to your change, but I suspect they are not (master is broken too, but there are issues in progress working to fix it).

Thanks!
Bruno

@namannigam-zz

namannigam-zz commented Feb 18, 2019

Copy link
Copy Markdown

@kinow In Java-11, there has been an introduction to an API default <T> T[] toArray(IntFunction<T[]> generator) which does internally calls the same 0 sized array initialisation.
The construct for example in that case would be list.toArray(String[]::new) instead of list.toArray(new String[0]).

@kinow

kinow commented Feb 20, 2019

Copy link
Copy Markdown
Member

Thanks @namannigam . So I believe so far the overall consensus here is that the change in the pull request is OK. Let's give it some more time to wait for at least another developer to review it.

@asfgit asfgit closed this in bcb3604 Dec 25, 2019
@PascalSchumacher

Copy link
Copy Markdown
Contributor

Merged. Thank you very much for the pull request and sorry for the delay.

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.

4 participants