Skip to content

Commit a75877c

Browse files
committed
Massive speedup. FormatterFunc is instantiated lazily and is not involved in serialization/equality, so good to eagerly initialize in the constructor.
1 parent 735c7b5 commit a75877c

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lib/src/scalafmt/java/com/diffplug/spotless/glue/scalafmt/ScalafmtFormatterFunc.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,9 @@
3030
import scala.collection.immutable.Set$;
3131

3232
public class ScalafmtFormatterFunc implements FormatterFunc {
33-
private final FileSignature configSignature;
33+
private final ScalafmtConfig config;
3434

35-
public ScalafmtFormatterFunc(FileSignature configSignature) {
36-
this.configSignature = configSignature;
37-
}
38-
39-
@Override
40-
public String apply(String input) throws Exception {
41-
ScalafmtConfig config;
35+
public ScalafmtFormatterFunc(FileSignature configSignature) throws Exception {
4236
if (configSignature.files().isEmpty()) {
4337
// Note that reflection is used here only because Scalafmt has a method called
4438
// default which happens to be a reserved Java keyword. The only way to call
@@ -51,6 +45,10 @@ public String apply(String input) throws Exception {
5145
String configStr = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
5246
config = Scalafmt.parseHoconConfig(configStr).get();
5347
}
48+
}
49+
50+
@Override
51+
public String apply(String input) {
5452
return Scalafmt.format(input, config, Set$.MODULE$.empty()).get();
5553
}
5654
}

0 commit comments

Comments
 (0)