Skip to content

Commit

Permalink
Improve performance of schematic generator. (-30%)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rollczi committed Sep 27, 2023
1 parent bd5bfb1 commit da4f717
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ public class SchematicFormat {

private final String prefix;
private final String suffix;
private final String commandFormat;
private final String argumentFormat;
private final String optionalArgumentFormat;

SchematicFormat(String prefix, String suffix, String commandFormat, String argumentFormat, String optionalArgumentFormat) {
SchematicFormat(String prefix, String suffix, String argumentFormat, String optionalArgumentFormat) {
this.prefix = prefix;
this.suffix = suffix;
this.commandFormat = commandFormat;
this.argumentFormat = argumentFormat;
this.optionalArgumentFormat = optionalArgumentFormat;
}
Expand All @@ -24,10 +22,6 @@ public String suffix() {
return suffix;
}

public String commandFormat() {
return commandFormat;
}

public String argumentFormat() {
return argumentFormat;
}
Expand All @@ -37,19 +31,19 @@ public String optionalArgumentFormat() {
}

public static SchematicFormat of(String prefix, String suffix, String commandFormat, String argumentFormat, String optionalArgumentFormat) {
return new SchematicFormat(prefix, suffix, commandFormat, argumentFormat, optionalArgumentFormat);
return new SchematicFormat(prefix, suffix, argumentFormat, optionalArgumentFormat);
}

public static SchematicFormat angleBrackets() {
return new SchematicFormat("/", "", "%s", "<%s>", "[%s]");
return new SchematicFormat("/", "", "<%s>", "[%s]");
}

public static SchematicFormat squareBrackets() {
return new SchematicFormat("/", "", "%s", "[%s]", "<%s>");
return new SchematicFormat("/", "", "[%s]", "<%s>");
}

public static SchematicFormat parentheses() {
return new SchematicFormat("/", "", "%s", "(%s)", "(%s)");
return new SchematicFormat("/", "", "(%s)", "(%s)");
}

public static Builder builder() {
Expand All @@ -60,7 +54,6 @@ public static class Builder {

private String prefix = "/";
private String suffix = "";
private String command = "%s";
private String argument = "<%s>";
private String optionalArgument = "[%s]";

Expand All @@ -74,11 +67,6 @@ public Builder suffix(String suffix) {
return this;
}

public Builder command(String command) {
this.command = command;
return this;
}

public Builder argument(String argument) {
this.argument = argument;
return this;
Expand All @@ -90,7 +78,7 @@ public Builder optionalArgument(String optionalArgument) {
}

public SchematicFormat build() {
return new SchematicFormat(prefix, suffix, command, argument, optionalArgument);
return new SchematicFormat(prefix, suffix, argument, optionalArgument);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ public Schematic generate(SchematicInput<SENDER> schematicInput) {
private Stream<String> generateRaw(SchematicInput<SENDER> schematicInput) {
CommandExecutor<SENDER> executor = schematicInput.getExecutor();
String base = schematicInput.collectRoutes().stream()
.map(route -> String.format(format.commandFormat(), route.getName()) + SEPARATOR)
.collect(Collectors.joining());
.map(route -> route.getName())
.collect(Collectors.joining(SEPARATOR))
+ SEPARATOR;

if (executor != null) {
return Stream.of(base + generateExecutor(executor));
Expand Down

0 comments on commit da4f717

Please sign in to comment.