uschindler commented on code in PR #15823:
URL: https://github.com/apache/lucene/pull/15823#discussion_r3000489998
##########
lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java:
##########
@@ -193,15 +193,24 @@ public void addAll(Collection<T> elements) {
public void addAll(Stream<T> elements) {
// Heap with size S always takes first S elements of the array,
// and thus it's safe to fill array further - no actual non-sentinel value
will be overwritten.
- elements.forEach(
- element -> {
- this.heap[size + 1] = element;
- this.size++;
- });
-
- // The loop goes down to 1 as heap is 1-based not 0-based.
- for (int i = (size >>> 1); i >= 1; i--) {
- downHeap(i);
+ final int remainingSize = maxSize - this.size;
+ try {
+ elements.forEach(
+ element -> {
+ this.heap[size + 1] = element;
+ this.size++;
+ });
+
+ } catch (
+ @SuppressWarnings("unused")
+ ArrayIndexOutOfBoundsException e) {
Review Comment:
You can use "_" as name for the variable in main branch. then there are no
warnings. so suppress not needed. While backporting you need the code with
suppress.
Another suggestion: Maybe better use a generic `IndexOutOfBoundsException`
to describe the message.
I like it that you still clean up the heap after a failed addition.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]