From 41d0f3340284986fed4122004b7781dc4a64c7a8 Mon Sep 17 00:00:00 2001 From: Michael Froh Date: Fri, 10 Jan 2025 20:38:33 -0800 Subject: [PATCH] Move null-check out of loop Signed-off-by: Michael Froh --- .../org/opensearch/cluster/routing/OperationRouting.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/org/opensearch/cluster/routing/OperationRouting.java b/server/src/main/java/org/opensearch/cluster/routing/OperationRouting.java index d2432653918b5..eac6f41acde4c 100644 --- a/server/src/main/java/org/opensearch/cluster/routing/OperationRouting.java +++ b/server/src/main/java/org/opensearch/cluster/routing/OperationRouting.java @@ -285,8 +285,8 @@ public GroupShardsIterator searchShards( } } List allShardIterators = new ArrayList<>(); - for (List indexIterators : shardIterators.values()) { - if (slice != null) { + if (slice != null) { + for (List indexIterators : shardIterators.values()) { // Filter the returned shards for the given slice CollectionUtil.timSort(indexIterators); // We use the ordinal of the iterator in the group (after sorting) rather than the shard id, because @@ -300,9 +300,9 @@ public GroupShardsIterator searchShards( allShardIterators.add(indexIterators.get(i)); } } - } else { - allShardIterators.addAll(indexIterators); } + } else { + shardIterators.values().forEach(allShardIterators::addAll); } return GroupShardsIterator.sortAndCreate(allShardIterators);