Cache compiled pattern

This commit is contained in:
themode 2022-03-09 19:47:42 +01:00
parent d3432011d9
commit e7545e470f
1 changed files with 2 additions and 4 deletions

View File

@ -12,6 +12,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
final class ShapeImpl implements Shape {
private static final Pattern PATTERN = Pattern.compile("\\d.\\d{1,3}", Pattern.MULTILINE);
private final BoundingBox[] blockSections;
private final Supplier<Material> block;
@ -21,10 +22,7 @@ final class ShapeImpl implements Shape {
}
static ShapeImpl parseBlockFromRegistry(String str, Supplier<Material> block) {
final String regex = "\\d.\\d{1,3}";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(str);
final Matcher matcher = PATTERN.matcher(str);
DoubleList vals = new DoubleArrayList();
while (matcher.find()) {
double newVal = Double.parseDouble(matcher.group());