apache / lucene

Apache Lucene open-source search software
https://lucene.apache.org/
Apache License 2.0
2.45k stars 973 forks source link

Call ArrayUtil.copyArray instead of ArrayUtil.copySubArray for full array copy. #13360

Closed bruno-roustant closed 1 month ago

bruno-roustant commented 1 month ago

ArrayUtil provides copySubArray() as replacement of Array.copyOf and Array.copyOfRange (with better bounds check). Unfortunately ArrayUtil does not provide copyArray(), so it is weird for callers to have to call a method named copySubArray() when we want to copy the full array.

This PR adds ArrayUtil.copyArray(), and replaces the calls to ArrayUtil.copySubArray(array, 0, array.length) with calls to ArrayUtil.copyArray(array). I used the following regex to match all calls: copyOfSubArray\(([^,]+), 0, \1\.length\) and this one to replace copyArray($1)