On Thu, 26 Jan 2023 06:46:16 GMT, Glavo <d...@openjdk.org> wrote:

> I checked the `java.base` module, and all the `Collection#toArray()` method 
> of collections be implemented correctly.
> 
> Their return values can be trusted, so many unnecessary array duplication can 
> be eliminated.

You could also have a look into `PriorityQueue.initElementsFromCollection()`

@Glavo I've filed https://bugs.openjdk.org/browse/JDK-8301220 so you can use it 
for this PR.

src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java line 
746:

> 744:             int len = es.length;
> 745:             Object[] newElements;
> 746:             if (len == 0 && c.getClass().getModule() == 
> Object.class.getModule()) {

I think as soon as we anyway assign the array from trusted collection, we don't 
need `len == 0` check here any more

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

PR: https://git.openjdk.org/jdk/pull/12212

Reply via email to