You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ja...@apache.org on 2026/08/20 12:32:08 UTC

(lucene) branch main updated: Simplify array copy by ArrayUtil.copyOfSubArray() in grouping package (#16516)

This is an automated email from the ASF dual-hosted git repository.

javanna pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/main by this push:
     new 897625db0f9 Simplify array copy by ArrayUtil.copyOfSubArray() in grouping package (#16516)
897625db0f9 is described below

commit 897625db0f99dde8a37c68889521caa79e4902a3
Author: gaobinlong <gb...@amazon.com>
AuthorDate: Thu Aug 20 20:32:03 2026 +0800

    Simplify array copy by ArrayUtil.copyOfSubArray() in grouping package (#16516)
    
    Replace manual array copy by ArrayUtil.copyOfSubArray() in grouping package.
    
    Signed-off-by: Binlong Gao <gb...@amazon.com>
---
 lucene/CHANGES.txt                                            |  2 ++
 .../src/java/org/apache/lucene/search/grouping/TopGroups.java | 11 ++++-------
 .../test/org/apache/lucene/search/grouping/TestGrouping.java  |  4 ++--
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 8f59c576b25..37d08327c0c 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -515,6 +515,8 @@ Other
 * GITHUB#16300: Reduce memory pressure in TestTermInSetQuery.testDuel stress runs.
   (Sanghun Lee)
 
+* GITHUB#16516: Simplify array copy by ArrayUtil.copyOfSubArray() in grouping package (Binlong Gao)
+
 ======================= Lucene 10.5.1 =======================
 
 Bug Fixes
diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java
index 9d496fa5163..4d4c5f81823 100644
--- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java
+++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java
@@ -30,6 +30,7 @@ import org.apache.lucene.search.TopDocs;
 import org.apache.lucene.search.TopFieldDocs;
 import org.apache.lucene.search.TotalHits;
 import org.apache.lucene.search.TotalHits.Relation;
+import org.apache.lucene.util.ArrayUtil;
 
 /**
  * Represents result returned by a grouping search.
@@ -253,13 +254,9 @@ public class TopGroups<T> {
       } else if (docOffset >= mergedTopDocs.scoreDocs.length) {
         mergedScoreDocs = new ScoreDoc[0];
       } else {
-        mergedScoreDocs = new ScoreDoc[mergedTopDocs.scoreDocs.length - docOffset];
-        System.arraycopy(
-            mergedTopDocs.scoreDocs,
-            docOffset,
-            mergedScoreDocs,
-            0,
-            mergedTopDocs.scoreDocs.length - docOffset);
+        mergedScoreDocs =
+            ArrayUtil.copyOfSubArray(
+                mergedTopDocs.scoreDocs, docOffset, mergedTopDocs.scoreDocs.length);
       }
 
       final float groupScore;
diff --git a/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java b/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java
index 9e3c95b942d..6d24a9db37e 100644
--- a/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java
+++ b/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java
@@ -68,6 +68,7 @@ import org.apache.lucene.tests.analysis.MockAnalyzer;
 import org.apache.lucene.tests.index.RandomIndexWriter;
 import org.apache.lucene.tests.util.LuceneTestCase;
 import org.apache.lucene.tests.util.TestUtil;
+import org.apache.lucene.util.ArrayUtil;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.mutable.MutableValue;
 import org.apache.lucene.util.mutable.MutableValueStr;
@@ -947,8 +948,7 @@ public class TestGrouping extends LuceneTestCase {
         }
       }
 
-      final GroupDoc[] groupDocsByID = new GroupDoc[groupDocs.length];
-      System.arraycopy(groupDocs, 0, groupDocsByID, 0, groupDocs.length);
+      final GroupDoc[] groupDocsByID = ArrayUtil.copyOfSubArray(groupDocs, 0, groupDocs.length);
 
       final DirectoryReader r = w.getReader();
       w.close();