You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "sabi0 (via GitHub)" <gi...@apache.org> on 2023/12/24 22:53:12 UTC

[PR] Use Collections.addAll() instead of manual array copy [lucene]

sabi0 opened a new pull request, #12977:
URL: https://github.com/apache/lucene/pull/12977

   (no comment)


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Use Collections.addAll() instead of manual array copy and misc. code cleanups [lucene]

Posted by "dweiss (via GitHub)" <gi...@apache.org>.
dweiss merged PR #12977:
URL: https://github.com/apache/lucene/pull/12977


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Use Collections.addAll() instead of manual array copy and misc. code cleanups [lucene]

Posted by "sabi0 (via GitHub)" <gi...@apache.org>.
sabi0 commented on code in PR #12977:
URL: https://github.com/apache/lucene/pull/12977#discussion_r1444287508


##########
lucene/misc/src/java/org/apache/lucene/misc/index/IndexSplitter.java:
##########
@@ -67,18 +66,10 @@ public static void main(String[] args) throws Exception {
     if (args[1].equals("-l")) {
       is.listSegments();
     } else if (args[1].equals("-d")) {
-      List<String> segs = new ArrayList<>();
-      for (int x = 2; x < args.length; x++) {
-        segs.add(args[x]);
-      }
-      is.remove(segs.toArray(new String[0]));
+      is.remove(Arrays.copyOfRange(args, 2, args.length));

Review Comment:
   Thank you.



-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Use Collections.addAll() instead of manual array copy [lucene]

Posted by "dweiss (via GitHub)" <gi...@apache.org>.
dweiss commented on code in PR #12977:
URL: https://github.com/apache/lucene/pull/12977#discussion_r1442253173


##########
lucene/misc/src/java/org/apache/lucene/misc/index/IndexSplitter.java:
##########
@@ -67,18 +66,10 @@ public static void main(String[] args) throws Exception {
     if (args[1].equals("-l")) {
       is.listSegments();
     } else if (args[1].equals("-d")) {
-      List<String> segs = new ArrayList<>();
-      for (int x = 2; x < args.length; x++) {
-        segs.add(args[x]);
-      }
-      is.remove(segs.toArray(new String[0]));
+      is.remove(Arrays.copyOfRange(args, 2, args.length));

Review Comment:
   I allowed myself to correct this one and push it to your branch.



-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Use Collections.addAll() instead of manual array copy [lucene]

Posted by "dweiss (via GitHub)" <gi...@apache.org>.
dweiss commented on code in PR #12977:
URL: https://github.com/apache/lucene/pull/12977#discussion_r1441428909


##########
lucene/misc/src/java/org/apache/lucene/misc/index/IndexSplitter.java:
##########
@@ -67,18 +66,10 @@ public static void main(String[] args) throws Exception {
     if (args[1].equals("-l")) {
       is.listSegments();
     } else if (args[1].equals("-d")) {
-      List<String> segs = new ArrayList<>();
-      for (int x = 2; x < args.length; x++) {
-        segs.add(args[x]);
-      }
-      is.remove(segs.toArray(new String[0]));
+      is.remove(Arrays.copyOfRange(args, 2, args.length));

Review Comment:
   This passes validation checks only because the method is suppressed from checks - it uses the sysouts. Arrays.copyOfRange is on the forbidden APIs list, it should be replaced with:
   
   java.util.Arrays#copyOfRange(**) @ Prefer using ArrayUtil as Arrays#copyOfRange fills zeros for bad bounds
   
   



-- 
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-unsubscribe@lucene.apache.org

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


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