On Wed, 8 Jul 2026 23:39:35 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 two > additional commits since the last revision: > > - Revert changes for initElementsFromCollection > - review src/java.base/share/classes/java/util/PriorityQueue.java line 356: > 354: @Override > 355: public boolean addAll(Collection<? extends E> c) { > 356: if (size == 0 && getClass() == PriorityQueue.class) { If policy is now going to be all-or-nothing for addAll, I think we can do some tricks to get rid of empty requirement. 1. Make grow() static and return an object array. 2. Copy element into the unpublished (grown or safe) copy. 3. Heapify that copy. 4. Assign to this.queue and increment this.size. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/31701#discussion_r3548348047
