Skip to content

Commit d51ed9b

Browse files
committed
Unrelated: Optimize performance of SourceCodeLocation
Once again surprising, but for sufficiently many classes it has a noticeable performance impact to use `String.format(..)` instead of `StringBuilder` (which constant string concatenation will be compiled to in the byte code for all non-ancient JDK versions I know). Since we create the formatted source code location for every class in the import this scales linear with the number of classes. Signed-off-by: Peter Gafert <[email protected]>
1 parent 16a6261 commit d51ed9b

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

archunit/src/main/java/com/tngtech/archunit/core/domain/SourceCodeLocation.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
*/
4141
@PublicAPI(usage = ACCESS)
4242
public final class SourceCodeLocation {
43-
private static final String LOCATION_TEMPLATE = "(%s:%d)";
4443

4544
@PublicAPI(usage = ACCESS)
4645
public static SourceCodeLocation of(JavaClass sourceClass) {
@@ -57,7 +56,7 @@ private static String formatLocation(JavaClass sourceClass, int lineNumber) {
5756
? sourceClass.getSource().get().getFileName()
5857
: Optional.<String>absent();
5958
String sourceFileName = recordedSourceFileName.isPresent() ? recordedSourceFileName.get() : guessSourceFileName(sourceClass);
60-
return String.format(LOCATION_TEMPLATE, sourceFileName, lineNumber);
59+
return "(" + sourceFileName + ":" + lineNumber + ")";
6160
}
6261

6362
private static String guessSourceFileName(JavaClass location) {

0 commit comments

Comments
 (0)