|
30 | 30 | import java.nio.file.Path; |
31 | 31 | import java.nio.file.Paths; |
32 | 32 | import java.util.ArrayList; |
33 | | -import java.util.Arrays; |
34 | 33 | import java.util.Collections; |
35 | 34 | import java.util.HashMap; |
36 | 35 | import java.util.List; |
37 | 36 | import java.util.Map; |
38 | | -import java.util.regex.Pattern; |
39 | 37 |
|
40 | 38 | public class AccessTransformerList { |
41 | 39 | private static final Logger LOGGER = LogManager.getLogger("AXFORM"); |
@@ -125,20 +123,42 @@ public void load(Path path, String resourceName, List<String> lines) { |
125 | 123 | LOGGER.debug(AXFORM_MARKER,"Loaded access transformer {} from path {}", resourceName, path); |
126 | 124 | } |
127 | 125 |
|
128 | | - private static Pattern WHITESPACE = Pattern.compile("[ \t]+"); |
129 | | - |
130 | 126 | 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 | | - } |
139 | 127 | if (line.length() == 0) |
140 | 128 | 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; |
142 | 162 | } |
143 | 163 |
|
144 | 164 | private void mergeAccessTransformers(List<AccessTransformer> atList, Map<Target<?>, AccessTransformer> accessTransformers, String resourceName) { |
|
0 commit comments