On Wed, 8 Jul 2026 18:55:13 GMT, Viktor Klang <[email protected]> wrote:
>> 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? 🤔 Thanks, I think there may be a small confusion here. The exact `PriorityQueue` check is only for the receiver. The source collection `c` can still be any `Collection`, so `prepareElements` is still needed there. I agree with the refactoring suggestion, though. I will fold the `initElementsFromArray` logic into the callers and remove that helper. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/31701#discussion_r3546796518
