Skip to content

Commit 7c842b2

Browse files
committed
Skip RegEx for tokenize
1 parent 45d9579 commit 7c842b2

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

src/main/java/net/minecraftforge/accesstransformer/parser/AccessTransformerList.java

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@
3030
import java.nio.file.Path;
3131
import java.nio.file.Paths;
3232
import java.util.ArrayList;
33-
import java.util.Arrays;
3433
import java.util.Collections;
3534
import java.util.HashMap;
3635
import java.util.List;
3736
import java.util.Map;
38-
import java.util.regex.Pattern;
3937

4038
public class AccessTransformerList {
4139
private static final Logger LOGGER = LogManager.getLogger("AXFORM");
@@ -125,20 +123,42 @@ public void load(Path path, String resourceName, List<String> lines) {
125123
LOGGER.debug(AXFORM_MARKER,"Loaded access transformer {} from path {}", resourceName, path);
126124
}
127125

128-
private static Pattern WHITESPACE = Pattern.compile("[ \t]+");
129-
130126
private static List<String> tokenize(String line) {
131-
int idx = line.indexOf('#');
132-
if (idx != -1) {
133-
while (idx > 1 && (line.charAt(idx - 1) == ' ' || line.charAt(idx - 1) == '\t'))
134-
idx--;
135-
if (idx == 0)
136-
return Collections.emptyList();
137-
line = line.substring(0, idx);
138-
}
139127
if (line.length() == 0)
140128
return Collections.emptyList();
141-
return Arrays.asList(WHITESPACE.split(line));
129+
130+
// This is unrolled instead of using String.split because that uses RegEx in the back end which is slow
131+
List<String> ret = new ArrayList<>();
132+
int start = 0;
133+
for (int x = 0; x < line.length(); x++) {
134+
char c = line.charAt(x);
135+
if (c == ' ' || c == '\t') {
136+
if (start == x)
137+
ret.add("");
138+
else
139+
ret.add(line.substring(start, x));
140+
141+
// Skip all consecutive whitespace
142+
do {
143+
x++;
144+
if (x == line.length())
145+
break;
146+
c = line.charAt(x);
147+
} while (c == ' ' || c == '\t');
148+
149+
if (c == '#')
150+
break;
151+
152+
start = x--;
153+
} else if (x == line.length() - 1) {
154+
ret.add(line.substring(start));
155+
} else if (c == '#') {
156+
if (start != x)
157+
ret.add(line.substring(start, x));
158+
break;
159+
}
160+
}
161+
return ret;
142162
}
143163

144164
private void mergeAccessTransformers(List<AccessTransformer> atList, Map<Target<?>, AccessTransformer> accessTransformers, String resourceName) {

0 commit comments

Comments
 (0)