On Tue, 7 Jul 2026 20:47:42 GMT, Daisuke Yamazaki <[email protected]> wrote:

>> Added a fast path for `PriorityQueue#addAll` when adding elements to an 
>> empty, exact `PriorityQueue` instance.
>> 
>> Instead of inserting each element one by one through `AbstractQueue#addAll`,
>> the implementation now copies the source collection into the backing array 
>> and calls `heapify()`.
>> This reduces the construction cost for bulk insertion into an empty queue 
>> from repeated per-element sift-up work to linear-time heap construction.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Daisuke Yamazaki has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Revert redundant styling

src/java.base/share/classes/java/util/PriorityQueue.java line 298:

> 296:     }
> 297: 
> 298:     private Object[] prepareElements(Collection<? extends E> c) {

Making this method static would be preferable, since there is no reason for it 
to depend on instance state.

src/java.base/share/classes/java/util/PriorityQueue.java line 308:

> 306:         if (cClass != ArrayList.class)
> 307:             es = Arrays.copyOf(es, len, Object[].class);
> 308:         if (len == 1 || this.comparator != null)

A comment explaining the `len == 1`-case would be good

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

PR Review Comment: https://git.openjdk.org/jdk/pull/31701#discussion_r3542931196
PR Review Comment: https://git.openjdk.org/jdk/pull/31701#discussion_r3542936443

Reply via email to