On Wed, Apr 22, 2020 at 3:13 PM <ma...@apache.org> wrote: > This is an automated email from the ASF dual-hosted git repository. > > markt pushed a commit to branch 9.0.x > in repository https://gitbox.apache.org/repos/asf/tomcat.git > > > The following commit(s) were added to refs/heads/9.0.x by this push: > new 76c681b Use empty arrays for Collections.toArray() > 76c681b is described below > > commit 76c681bc1acfd65615a985b6adf527bcc21c18e9 > Author: Lars Grefer <lars.gre...@materna.de> > AuthorDate: Tue Apr 7 18:09:26 2020 +0200 > > Use empty arrays for Collections.toArray() > > There are two styles to convert a collection to an array: > either using a pre-sized array (like c.toArray(new String[c.size()])) > or using an empty array (like c.toArray(new String[0]). > > In older Java versions using pre-sized array was recommended, > as the reflection call which is necessary to create an array of proper > size was quite slow. > However since late updates of OpenJDK 6 this call was intrinsified, > making the performance of the empty array version the same and > sometimes even better, > compared to the pre-sized version. > > See also: https://shipilev.net/blog/2016/arrays-wisdom-ancients/ >
It says that using a real constant for the 0-size array is not meaningfully faster, so that's good as well. Rémy