|
11 | 11 | package org.junit.jupiter.params;
|
12 | 12 |
|
13 | 13 | import static java.util.Objects.requireNonNull;
|
14 |
| -import static java.util.stream.Collectors.joining; |
15 | 14 | import static org.junit.jupiter.params.ParameterizedInvocationConstants.ARGUMENTS_PLACEHOLDER;
|
16 | 15 | import static org.junit.jupiter.params.ParameterizedInvocationConstants.ARGUMENTS_WITH_NAMES_PLACEHOLDER;
|
17 | 16 | import static org.junit.jupiter.params.ParameterizedInvocationConstants.ARGUMENT_SET_NAME_OR_ARGUMENTS_WITH_NAMES_PLACEHOLDER;
|
|
30 | 29 | import java.util.Map;
|
31 | 30 | import java.util.Optional;
|
32 | 31 | import java.util.Set;
|
| 32 | +import java.util.StringJoiner; |
33 | 33 | import java.util.concurrent.ConcurrentHashMap;
|
34 | 34 | import java.util.concurrent.ConcurrentMap;
|
35 | 35 | import java.util.function.Function;
|
36 |
| -import java.util.stream.IntStream; |
37 | 36 |
|
38 | 37 | import org.jspecify.annotations.Nullable;
|
39 | 38 | import org.junit.jupiter.api.extension.ExtensionConfigurationException;
|
|
48 | 47 | */
|
49 | 48 | class ParameterizedInvocationNameFormatter {
|
50 | 49 |
|
| 50 | + /** |
| 51 | + * Global cache for {arguments} pattern strings, keyed by the number of arguments. |
| 52 | + * @since 6.0 |
| 53 | + */ |
| 54 | + private static final Map<Integer, String> argumentsPatternCache = new ConcurrentHashMap<>(8); |
| 55 | + |
51 | 56 | static final String DEFAULT_DISPLAY_NAME = "{default_display_name}";
|
52 | 57 | static final String DEFAULT_DISPLAY_NAME_PATTERN = "[" + INDEX_PLACEHOLDER + "] "
|
53 | 58 | + ARGUMENT_SET_NAME_OR_ARGUMENTS_WITH_NAMES_PLACEHOLDER;
|
@@ -186,9 +191,14 @@ private PartialFormatters createPartialFormatters(String displayName,
|
186 | 191 | }
|
187 | 192 |
|
188 | 193 | private static String argumentsPattern(int length) {
|
189 |
| - return IntStream.range(0, length) // |
190 |
| - .mapToObj(index -> "{" + index + "}") // |
191 |
| - .collect(joining(", ")); |
| 194 | + return argumentsPatternCache.computeIfAbsent(length, // |
| 195 | + key -> { |
| 196 | + StringJoiner sj = new StringJoiner(", "); |
| 197 | + for (int i = 0; i < length; i++) { |
| 198 | + sj.add("{" + i + "}"); |
| 199 | + } |
| 200 | + return sj.toString(); |
| 201 | + }); |
192 | 202 | }
|
193 | 203 |
|
194 | 204 | private record PlaceholderPosition(int index, String placeholder) {
|
|
0 commit comments