RFR: 8193031: Collections.addAll is likely to perform worse than Collection.addAll

Сергей Цыпанов github.com+10835776+stsypanov at openjdk.java.net
Tue Dec 29 20:43:13 UTC 2020


On Tue, 29 Dec 2020 10:56:02 GMT, Peter Levart <plevart at openjdk.org> wrote:

>> Hint: you could use `java.util.ImmutableCollections#listFromTrustedArrayNullsAllowed` if only this method would allow other types of arrays, not just Object[]... I really don't know why this restriction couldn't be lifted as the captured array is fully encapsulated.
>
> On a second thought, using `java.util.ImmutableCollections#listFromTrustedArrayNullsAllowed` is not a good idea, since the method expects the passed-in array to be trusted and use of this method in `Collections.addAll(col, array)` would wrap an untrusted array. Surely the resulting List would only be used as an argument to `col.addAll(list)`, but since neither `col` is trusted, it could "steal" the passed-in `list` and use it...
> Some other implementation of immutable list array wrapper would be needed here.

@plevart hi, I've decided to revert implementation change and keep only the change in JavaDoc because it's performance-related part is often referenced to while being incorrect in most of cases.

-------------

PR: https://git.openjdk.java.net/jdk/pull/1764


More information about the core-libs-dev mailing list