On Wed, 8 Jul 2026 10:43:51 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: > > Make heapify static src/java.base/share/classes/java/util/PriorityQueue.java line 376: > 374: throw new NullPointerException(); > 375: if (c == this) > 376: throw new IllegalArgumentException(); I think these two checks should be made just inside the `if (size == 0 && getClass() == PriorityQueue.class) {`-block, as otherwise we'll check those invariants twice if we end up calling super.addAll(c). src/java.base/share/classes/java/util/PriorityQueue.java line 386: > 384: initElementsFromArray(es); > 385: > 386: this.modCount++; modCount should be incremented *before* the modification is done, and does not need to be dereferenced via `this.` (just like `size == 0` isn't dereferenced via `this.`) ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/31701#discussion_r3544732922 PR Review Comment: https://git.openjdk.org/jdk/pull/31701#discussion_r3544724014
