Skip to content

Commit 0003000

Browse files
committed
java: Optimize StringUtils
Avoid unboxing to Character
1 parent f3cc6b0 commit 0003000

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

java/src/main/java/io/cucumber/gherkin/PickleCompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private PickleTable pickleDataTable(DataTable dataTable, List<TableCell> variabl
187187
List<PickleTableRow> newRows = new ArrayList<>(rows.size());
188188
for (TableRow row : rows) {
189189
List<TableCell> cells = row.getCells();
190-
List<PickleTableCell> newCells = new ArrayList<>();
190+
List<PickleTableCell> newCells = new ArrayList<>(cells.size());
191191
for (TableCell cell : cells) {
192192
newCells.add(new PickleTableCell(interpolate(cell.getValue(), variableCells, valueCells)));
193193
}

java/src/main/java/io/cucumber/gherkin/StringUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private static int findFirstIndexIn(String input, char[] characters) {
106106
}
107107

108108
private static boolean contains(char[] characters, char c) {
109-
for (Character candidate : characters) {
109+
for (char candidate : characters) {
110110
if (candidate == c) {
111111
return true;
112112
}

java/src/test/java/io/cucumber/gherkin/GherkinParserTest.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
import java.io.IOException;
1515
import java.io.InputStream;
1616
import java.nio.charset.StandardCharsets;
17+
import java.nio.file.Paths;
18+
import java.util.List;
1719
import java.util.Optional;
1820
import java.util.stream.Stream;
1921

2022
import static io.cucumber.messages.types.SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN;
23+
import static java.util.stream.Collectors.toList;
2124
import static org.junit.jupiter.api.Assertions.assertEquals;
2225
import static org.junit.jupiter.api.Assertions.assertTrue;
2326

@@ -37,14 +40,23 @@ void use_this_in_readme() {
3740
}
3841

3942
@Test
40-
void can_parse_streams() throws IOException {
41-
try (InputStream is = new ByteArrayInputStream(feature.getBytes(StandardCharsets.UTF_8))){
42-
GherkinParser parser = GherkinParser.builder().build();
43-
Stream<Envelope> pickles = parser.parse("minimal.feature",is).filter(envelope -> envelope.getPickle().isPresent());
44-
assertEquals(1, pickles.count());
43+
void test_for_profiler_parser() throws IOException {
44+
for (int i = 0; i < 1000; i++) {
45+
GherkinParser.builder().build().parse(Paths.get("../testdata/good/very_long.feature"));
4546
}
4647
}
4748

49+
@Test
50+
void can_parse_streams() throws IOException {
51+
InputStream is = new ByteArrayInputStream(feature.getBytes(StandardCharsets.UTF_8));
52+
GherkinParser parser = GherkinParser.builder()
53+
.includeSource(false)
54+
.includeGherkinDocument(false)
55+
.build();
56+
List<Envelope> pickles = parser.parse("minimal.feature", is).collect(toList());
57+
assertTrue(pickles.get(0).getPickle().isPresent());
58+
}
59+
4860
@Test
4961
void provides_access_to_the_ast() {
5062
// Get the AST

0 commit comments

Comments
 (0)