You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/10/23 19:26:07 UTC

[GitHub] [maven] gnodet commented on a diff in pull request #846: change goal type to StringBuilder

gnodet commented on code in PR #846:
URL: https://github.com/apache/maven/pull/846#discussion_r1002756710


##########
maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoDescriptorCreator.java:
##########
@@ -225,10 +225,10 @@ else if ( numTokens == 3 )
             plugin = findPluginForPrefix( prefix, session );
         }
 
-        int executionIdx = goal.indexOf( '@' );
+        int executionIdx = goal.toString().indexOf( '@' );

Review Comment:
   maybe `goal.indexOf( "@" )` to avoid the string conversion ?



##########
maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoDescriptorCreator.java:
##########
@@ -225,10 +225,10 @@ else if ( numTokens == 3 )
             plugin = findPluginForPrefix( prefix, session );
         }
 
-        int executionIdx = goal.indexOf( '@' );
+        int executionIdx = goal.toString().indexOf( '@' );
         if ( executionIdx > 0 )
         {
-            goal = goal.substring( 0, executionIdx );
+            goal = new StringBuilder(goal.substring(0, executionIdx));

Review Comment:
   That looks like the kind of operation we'd like to avoid : a conversion to String, and a conversion back to a StringBuilder.  Use `goal.setLength( executionIdx )` ?
   Not sure of the overall benefit if we manipulate `StringBuilder` to avoid a few string manipulation.   Maybe the use of the `StringBuilder` could be limited to refactoring the following code:
   ```
                goal = tok.nextToken();
   
                // This won't be valid, but it constructs something easy to read in the error message
                while ( tok.hasMoreTokens() )
                {
                    goal += ":" + tok.nextToken();
                }
   ```   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org