Re: [commons-lang] branch master updated: Use Collection#toArray(new T[0]) instead of a presized array as it is faster on modern JVMs.

2019-12-29 Thread Rob Spoor
One possible reason to use T[0] is because that's how the new (since Java 11) toArray method does it. From java.util.Collection, OpenJDK version 13: default T[] toArray(IntFunction generator) { return toArray(generator.apply(0)); } This method has, as of yet, not been overridd

Re: [commons-lang] branch master updated: Use Collection#toArray(new T[0]) instead of a presized array as it is faster on modern JVMs.

2019-12-28 Thread sebb
On Fri, 27 Dec 2019 at 17:43, Matt Sicker wrote: > It's somewhat logical, though, that T[0] is faster than T[size]. In > both cases, the given array is checked to see if it's large enough to > fit the collection contents. If it isn't, then a new array is > allocated. By deferring the new array al

Re: [commons-lang] branch master updated: Use Collection#toArray(new T[0]) instead of a presized array as it is faster on modern JVMs.

2019-12-27 Thread Matt Sicker
It's somewhat logical, though, that T[0] is faster than T[size]. In both cases, the given array is checked to see if it's large enough to fit the collection contents. If it isn't, then a new array is allocated. By deferring the new array allocation operation to the toArray() method call, you avoid

Re: [commons-lang] branch master updated: Use Collection#toArray(new T[0]) instead of a presized array as it is faster on modern JVMs.

2019-12-27 Thread Gary Gregory
I wonder where this should be documented. We could add a // comment to each call site, that seems the simplest. Adding a package or component level documentation in the style guideline for example could easily be overlooked by someone in a debugger for example. So each call site would be best IMO s

Re: [commons-lang] branch master updated: Use Collection#toArray(new T[0]) instead of a presized array as it is faster on modern JVMs.

2019-12-27 Thread Pascal Schumacher
Feel free to revert the changes. I would revert my changes, but Garry did some follow-up changes so these would to be reverted first. Am 27.12.2019 um 12:33 schrieb sebb: As that article says in conclusion, T[0] seems currently faster, but that may not always be the case with future VMs. Also

Re: [commons-lang] branch master updated: Use Collection#toArray(new T[0]) instead of a presized array as it is faster on modern JVMs.

2019-12-27 Thread sebb
As that article says in conclusion, T[0] seems currently faster, but that may not always be the case with future VMs. Also it says that IntelliJ IDEA and PMD recommend using T[size] rather than T[0]. If we release code with T[0], I suspect we will get complaints that the code is not efficient acco

Re: [commons-lang] branch master updated: Use Collection#toArray(new T[0]) instead of a presized array as it is faster on modern JVMs.

2019-12-27 Thread Pascal Schumacher
see https://shipilev.net/blog/2016/arrays-wisdom-ancients/ Am 27.12.2019 um 01:24 schrieb sebb: Also, where is it documented that modern JVMs are faster? To which JVMs does this apply? S. On Thu, 26 Dec 2019 at 22:08, Gary Gregory wrote: Please do not cause garbage to apparently be generate

Re: [commons-lang] branch master updated: Use Collection#toArray(new T[0]) instead of a presized array as it is faster on modern JVMs.

2019-12-26 Thread Gary Gregory
It certainly is not obvious from looking at the JRE method that calling toArray this way is faster... some // comments would be nice. Gary On Thu, Dec 26, 2019 at 7:25 PM sebb wrote: > Also, where is it documented that modern JVMs are faster? > To which JVMs does this apply? > > S. > > On Thu,

Re: [commons-lang] branch master updated: Use Collection#toArray(new T[0]) instead of a presized array as it is faster on modern JVMs.

2019-12-26 Thread sebb
Also, where is it documented that modern JVMs are faster? To which JVMs does this apply? S. On Thu, 26 Dec 2019 at 22:08, Gary Gregory wrote: > Please do not cause garbage to apparently be generated all over the place > by creating new empty arrays all the time. Use the constants Commons Lang >

Re: [commons-lang] branch master updated: Use Collection#toArray(new T[0]) instead of a presized array as it is faster on modern JVMs.

2019-12-26 Thread Gary Gregory
Please do not cause garbage to apparently be generated all over the place by creating new empty arrays all the time. Use the constants Commons Lang constants already defines; see ArrayUtils. Gary On Thu, Dec 26, 2019 at 4:48 PM wrote: > This is an automated email from the ASF dual-hosted git re