On Wed, 8 Jul 2026 18:12:34 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 three > additional commits since the last revision: > > - Clarify null-check comment in prepareElements > - Avoid duplicate argument checks in addAll > - Change modCount place and remove this access src/java.base/share/classes/java/util/PriorityQueue.java line 381: > 379: return false; > 380: > 381: Object[] es = prepareElements(c, comparator); What's the purpose of calling `prepareElements` here? We know `c` is exactly PriorityQueue, and PriorityQueue does not allow `null`-elements? I think `initElementsFromArray` can be removed, and its logic embedded directly into `addAll` and `initElementsFromCollection`, and if `prepareElements` isn't needed in `addAll` then `prepareElements` can be removed as a method and its logic be moved directly into `initElementsFromCollection`. Am I missing something? 🤔 ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/31701#discussion_r3546532767
