Skip to content

Commit 65b4607

Browse files
committed
Replace stream with loop in RequestCondition's
1 parent 9d6592d commit 65b4607

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/HeadersRequestCondition.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,13 @@ public int compareTo(HeadersRequestCondition other, ServerWebExchange exchange)
142142
}
143143

144144
private long getValueMatchCount(Set<HeaderExpression> expressions) {
145-
return expressions.stream().filter(e -> e.getValue() != null && !e.isNegated()).count();
145+
long count = 0;
146+
for (HeaderExpression e : expressions) {
147+
if (e.getValue() != null && !e.isNegated()) {
148+
count++;
149+
}
150+
}
151+
return count;
146152
}
147153

148154

spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ParamsRequestCondition.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ public int compareTo(ParamsRequestCondition other, ServerWebExchange exchange) {
124124
}
125125

126126
private long getValueMatchCount(Set<ParamExpression> expressions) {
127-
return expressions.stream().filter(e -> e.getValue() != null && !e.isNegated()).count();
127+
long count = 0;
128+
for (ParamExpression e : expressions) {
129+
if (e.getValue() != null && !e.isNegated()) {
130+
count++;
131+
}
132+
}
133+
return count;
128134
}
129135

130136

spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/PatternsRequestCondition.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.Set;
2525
import java.util.SortedSet;
2626
import java.util.TreeSet;
27-
import java.util.stream.Collectors;
2827

2928
import org.springframework.http.server.PathContainer;
3029
import org.springframework.lang.Nullable;
@@ -53,7 +52,7 @@ public PatternsRequestCondition(PathPattern... patterns) {
5352
}
5453

5554
/**
56-
* Creates a new instance with the given {@code Stream} of URL patterns.
55+
* Creates a new instance with the given URL patterns.
5756
*/
5857
public PatternsRequestCondition(List<PathPattern> patterns) {
5958
this(new TreeSet<>(patterns));
@@ -136,9 +135,13 @@ public PatternsRequestCondition getMatchingCondition(ServerWebExchange exchange)
136135
*/
137136
private SortedSet<PathPattern> getMatchingPatterns(ServerWebExchange exchange) {
138137
PathContainer lookupPath = exchange.getRequest().getPath().pathWithinApplication();
139-
return this.patterns.stream()
140-
.filter(pattern -> pattern.matches(lookupPath))
141-
.collect(Collectors.toCollection(TreeSet::new));
138+
TreeSet<PathPattern> pathPatterns = new TreeSet<>();
139+
for (PathPattern pattern : this.patterns) {
140+
if (pattern.matches(lookupPath)) {
141+
pathPatterns.add(pattern);
142+
}
143+
}
144+
return pathPatterns;
142145
}
143146

144147
/**

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/HeadersRequestCondition.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,13 @@ public int compareTo(HeadersRequestCondition other, HttpServletRequest request)
142142
}
143143

144144
private long getValueMatchCount(Set<HeaderExpression> expressions) {
145-
return expressions.stream().filter(e -> e.getValue() != null && !e.isNegated()).count();
145+
long count = 0;
146+
for (HeaderExpression e : expressions) {
147+
if (e.getValue() != null && !e.isNegated()) {
148+
count++;
149+
}
150+
}
151+
return count;
146152
}
147153

148154

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ParamsRequestCondition.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ public int compareTo(ParamsRequestCondition other, HttpServletRequest request) {
127127
}
128128

129129
private long getValueMatchCount(Set<ParamExpression> expressions) {
130-
return expressions.stream().filter(e -> e.getValue() != null && !e.isNegated()).count();
130+
long count = 0;
131+
for (ParamExpression e : expressions) {
132+
if (e.getValue() != null && !e.isNegated()) {
133+
count++;
134+
}
135+
}
136+
return count;
131137
}
132138

133139

0 commit comments

Comments
 (0)