Optimize some iterations in BodyExtractor and BodyInserter
This commit turns some stream-based iterations back into simpler enhanced for loops. For simple use cases like these, where the stream API is merely used to map/filter + collect to a List, a for loop is more efficient. This is especially true for small collections like the ones we deal with in BodyInserters/BodyExtractors here (in the order of 50ns/op vs 5ns/op). These cases are also simple enough that they don't lose in readability after the conversion. Closes gh-30136
This commit is contained in:
@@ -147,8 +147,10 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest {
|
||||
this.commitActions.add(writeAction);
|
||||
}
|
||||
|
||||
List<? extends Publisher<Void>> actions = this.commitActions.stream()
|
||||
.map(Supplier::get).toList();
|
||||
List<Publisher<Void>> actions = new ArrayList<>(this.commitActions.size());
|
||||
for (Supplier<? extends Publisher<Void>> commitAction : this.commitActions) {
|
||||
actions.add(commitAction.get());
|
||||
}
|
||||
|
||||
return Flux.concat(actions).then();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user