Skip to content

Commit 89d0d74

Browse files
committed
improvement with minimizing the creation of new strings in stripIllegalFilenameChars()
1 parent 53ea3ea commit 89d0d74

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterUtils.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,18 @@ private FileReporterUtils()
3535

3636
public static String stripIllegalFilenameChars( String original )
3737
{
38-
String result = original;
38+
StringBuilder result = new StringBuilder( original );
3939
String illegalChars = getOSSpecificIllegalChars();
40-
for ( int i = 0; i < illegalChars.length(); i++ )
40+
for ( int i = 0, len = result.length(); i < len; i++ )
4141
{
42-
result = result.replace( illegalChars.charAt( i ), '_' );
42+
char charFromOriginal = result.charAt( i );
43+
boolean isIllegalChar = illegalChars.indexOf( charFromOriginal ) != -1;
44+
if ( isIllegalChar )
45+
{
46+
result.setCharAt( i, '_' );
47+
}
4348
}
44-
45-
return result;
49+
return result.toString();
4650
}
4751

4852
private static String getOSSpecificIllegalChars()

0 commit comments

Comments
 (0)