Skip to content

Commit d1303af

Browse files
committed
Avoid expensive Stream API usage in HttpRange
See gh-22742
1 parent a089027 commit d1303af

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

spring-web/src/main/java/org/springframework/http/HttpRange.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ else if (dashIdx == 0) {
170170
* @param ranges the list of ranges
171171
* @param resource the resource to select the regions from
172172
* @return the list of regions for the given resource
173-
* @throws IllegalArgumentException if the sum of all ranges exceeds the
174-
* resource length.
173+
* @throws IllegalArgumentException if the sum of all ranges exceeds the resource length
175174
* @since 4.3
176175
*/
177176
public static List<ResourceRegion> toResourceRegions(List<HttpRange> ranges, Resource resource) {
@@ -184,7 +183,10 @@ public static List<ResourceRegion> toResourceRegions(List<HttpRange> ranges, Res
184183
}
185184
if (ranges.size() > 1) {
186185
long length = getLengthFor(resource);
187-
long total = regions.stream().map(ResourceRegion::getCount).reduce(0L, (count, sum) -> sum + count);
186+
long total = 0;
187+
for (ResourceRegion region : regions) {
188+
total += region.getCount();
189+
}
188190
if (total >= length) {
189191
throw new IllegalArgumentException("The sum of all ranges (" + total +
190192
") should be less than the resource length (" + length + ")");

0 commit comments

Comments
 (0)