Collections.emptyList().spliterator() is not ORDERED
Paul Sandoz
paul.sandoz at oracle.com
Mon Sep 7 13:23:33 UTC 2015
On 7 Sep 2015, at 11:20, Tagir F. Valeev <amaembo at gmail.com> wrote:
> PS> In this case we should fix Stream.concat to check if a
> PS> spliterator reporting SIZED is empty, which will allow us to optimize the concatenation [1].
> PS> [1] https://bugs.openjdk.java.net/browse/JDK-8022805
>
> That would be even better from performance point of view. Thanks.
>
Yes, there is a happy side to this :-)
> By the way, probably it's reasonable then for Arrays.asList to check
> the array length like:
>
> public static <T> List<T> asList(T... a) {
> if(a.length == 0)
> return Collections.emptyList();
> return new ArrayList<>(a);
> }
>
> This would make Arrays.asList() (without arguments) and
> Collections.emptyList() perfectly consistent (now their spliterators
> report different characteristics) and reduce the number of heap
> objects. Probably there are some caveats I'm not aware of. Sorry if it
> was already discussed.
>
This has not been discussed, it’s an edge case micro-optimisation but seems reasonable.
> PS> P.S. I still have a bunch of your stuff in my queue to process,
> PS> sorry it’s taking so long,i will get to them in the next couple of
> PS> weeks, but i need to process some other stuff first.
>
> No problems, I'm not in a hurry.
>
Ok, thanks,
Paul.
More information about the core-libs-dev
mailing list