You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2020/07/19 10:11:41 UTC

[maven-surefire] 04/04: improvement with minimizing the creation of new strings in stripIllegalFilenameChars()

This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch fastqueue
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git

commit 89d0d745a1c881bb68cfdd5efbdde113eb231e58
Author: tibordigana <ti...@apache.org>
AuthorDate: Sat Jul 18 23:22:36 2020 +0200

    improvement with minimizing the creation of new strings in stripIllegalFilenameChars()
---
 .../maven/plugin/surefire/report/FileReporterUtils.java    | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterUtils.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterUtils.java
index 5c0e5b1..5ef0610 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterUtils.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterUtils.java
@@ -35,14 +35,18 @@ public final class FileReporterUtils
 
     public static String stripIllegalFilenameChars( String original )
     {
-        String result = original;
+        StringBuilder result = new StringBuilder( original );
         String illegalChars = getOSSpecificIllegalChars();
-        for ( int i = 0; i < illegalChars.length(); i++ )
+        for ( int i = 0, len = result.length(); i < len; i++ )
         {
-            result = result.replace( illegalChars.charAt( i ), '_' );
+            char charFromOriginal = result.charAt( i );
+            boolean isIllegalChar = illegalChars.indexOf( charFromOriginal ) != -1;
+            if ( isIllegalChar )
+            {
+                result.setCharAt( i, '_' );
+            }
         }
-
-        return result;
+        return result.toString();
     }
 
     private static String getOSSpecificIllegalChars()