Skip to content

Commit 59631fd

Browse files
Remove redundant list copy in CanMatchNodeRequest (#121700)
We're not mutating that list ever, so lets just use an immutable list all the way here and avoid at least one round of needless copy.
1 parent fa3d548 commit 59631fd

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

server/src/main/java/org/elasticsearch/action/search/CanMatchNodeRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public CanMatchNodeRequest(
136136
) {
137137
this.source = getCanMatchSource(searchRequest);
138138
this.indicesOptions = indicesOptions;
139-
this.shards = new ArrayList<>(shards);
139+
this.shards = shards;
140140
this.searchType = searchRequest.searchType();
141141
this.requestCache = searchRequest.requestCache();
142142
// If allowPartialSearchResults is unset (ie null), the cluster-level default should have been substituted

server/src/main/java/org/elasticsearch/action/search/CanMatchPreFilterSearchPhase.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import java.util.concurrent.Executor;
4141
import java.util.concurrent.atomic.AtomicReferenceArray;
4242
import java.util.function.BiFunction;
43-
import java.util.stream.Collectors;
4443

4544
import static org.elasticsearch.core.Strings.format;
4645
import static org.elasticsearch.core.Types.forciblyCast;
@@ -348,10 +347,7 @@ private record SendingTarget(@Nullable String clusterAlias, @Nullable String nod
348347

349348
private CanMatchNodeRequest createCanMatchRequest(Map.Entry<SendingTarget, List<SearchShardIterator>> entry) {
350349
final SearchShardIterator first = entry.getValue().get(0);
351-
final List<CanMatchNodeRequest.Shard> shardLevelRequests = entry.getValue()
352-
.stream()
353-
.map(this::buildShardLevelRequest)
354-
.collect(Collectors.toCollection(ArrayList::new));
350+
final List<CanMatchNodeRequest.Shard> shardLevelRequests = entry.getValue().stream().map(this::buildShardLevelRequest).toList();
355351
assert entry.getValue().stream().allMatch(Objects::nonNull);
356352
assert entry.getValue()
357353
.stream()

0 commit comments

Comments
 (0)