stefanvodita commented on code in PR #12844:
URL: https://github.com/apache/lucene/pull/12844#discussion_r1422523818


##########
lucene/core/src/java/org/apache/lucene/util/ArrayUtil.java:
##########
@@ -330,15 +330,36 @@ public static int[] growExact(int[] array, int newLength) 
{
     return copy;
   }
 
+  /**
+   * Returns an array whose size is at least {@code minLength}, generally 
over-allocating
+   * exponentially, but never allocating more than {@code maxLength} elements.
+   */
+  public static int[] growInRange(int[] array, int minLength, int maxLength) {
+    assert minLength >= 0
+        : "length must be positive (got " + minLength + "): likely integer 
overflow?";
+
+    if (minLength > maxLength) {

Review Comment:
   Let's contrast this with the assertion above. A negative `minLength` is 
probably not intended, but we can techincally handle it, so we don't stop 
execution unless assertions are enabled. On the other hand, `minLength > 
maxLength` is not a case we can handle while obeying the contract of this 
method. I guess the contrast is unintended input vs invalid input. That's why I 
prefer the current arrangement, but let me know if you strongly feel otherwise.



-- 
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: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to