Skip to content

Commit 19ae50e

Browse files
committed
Optimized creation of distandes list in ShrinkingDistance.combine(..)
Working towards #435 effects
1 parent 38c1c9a commit 19ae50e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

api/src/main/java/net/jqwik/api/ShrinkingDistance.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.stream.*;
55

66
import org.apiguardian.api.*;
7+
import org.jetbrains.annotations.*;
78

89
import static org.apiguardian.api.API.Status.*;
910

@@ -41,9 +42,7 @@ public static <T> ShrinkingDistance combine(List<Shrinkable<T>> shrinkables) {
4142
throw new IllegalArgumentException("At least one shrinkable is required");
4243
}
4344
// This is an optimization to avoid creating many temporary arrays, which the old streams-based implementation did.
44-
List<long[]> shrinkableDistances = shrinkables.stream()
45-
.map(tShrinkable -> tShrinkable.distance().distances)
46-
.collect(Collectors.toList());
45+
List<long[]> shrinkableDistances = toDistances(shrinkables);
4746
long[] combinedDistances = concatenate(shrinkableDistances);
4847
return new ShrinkingDistance(combinedDistances);
4948
}
@@ -120,4 +119,14 @@ public ShrinkingDistance append(ShrinkingDistance other) {
120119
return new ShrinkingDistance(appendedDistances);
121120
}
122121

122+
@NotNull
123+
private static <T> List<long[]> toDistances(List<Shrinkable<T>> shrinkables) {
124+
List<long[]> listOfDistances = new ArrayList<>(shrinkables.size());
125+
for (Shrinkable<?> tShrinkable : shrinkables) {
126+
long[] longs = tShrinkable.distance().distances;
127+
listOfDistances.add(longs);
128+
}
129+
return listOfDistances;
130+
}
131+
123132
}

0 commit comments

Comments
 (0)