Skip to content

Commit 7e954bc

Browse files
Remove redundant list copy in CanMatchNodeRequest (elastic#121700) (elastic#121866)
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 a0f77e7 commit 7e954bc

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
@@ -41,7 +41,6 @@
4141
import java.util.concurrent.Executor;
4242
import java.util.concurrent.atomic.AtomicReferenceArray;
4343
import java.util.function.BiFunction;
44-
import java.util.stream.Collectors;
4544

4645
import static org.elasticsearch.core.Strings.format;
4746
import static org.elasticsearch.core.Types.forciblyCast;
@@ -350,10 +349,7 @@ private record SendingTarget(@Nullable String clusterAlias, @Nullable String nod
350349

351350
private CanMatchNodeRequest createCanMatchRequest(Map.Entry<SendingTarget, List<SearchShardIterator>> entry) {
352351
final SearchShardIterator first = entry.getValue().get(0);
353-
final List<CanMatchNodeRequest.Shard> shardLevelRequests = entry.getValue()
354-
.stream()
355-
.map(this::buildShardLevelRequest)
356-
.collect(Collectors.toCollection(ArrayList::new));
352+
final List<CanMatchNodeRequest.Shard> shardLevelRequests = entry.getValue().stream().map(this::buildShardLevelRequest).toList();
357353
assert entry.getValue().stream().allMatch(Objects::nonNull);
358354
assert entry.getValue()
359355
.stream()

0 commit comments

Comments
 (0)