Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-8475] In the loop scenario, StringBuilder is used instead of concatenation #2014

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

CrazyHZM
Copy link
Member

@CrazyHZM CrazyHZM commented Jan 1, 2025

Under loops, string concatenation using StringBuilder performs better.

@cstamas cstamas added this to the 4.0.0-rc-3 milestone Jan 3, 2025
if (executionIdx > 0) {
goal = goal.substring(0, executionIdx);
goal = new StringBuilder(goal.substring(0, executionIdx));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks inefficient, use goal.setLength(executionIdx);

@@ -216,9 +216,9 @@ public MojoDescriptor getMojoDescriptor(String task, MavenSession session, Maven
plugin = findPluginForPrefix(prefix, session);
}

int executionIdx = goal.indexOf('@');
int executionIdx = goal.toString().indexOf('@');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think wrt performances, it would be better to use goal.indexOf("@")

@@ -138,7 +138,7 @@ public MojoDescriptor getMojoDescriptor(String task, MavenSession session, Maven
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
PluginVersionResolutionException {
String goal = null;
StringBuilder goal = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think creating the new StringBuilder() here and use append in the 5 locations below instead of constructing a new StringBuilder would make the code more clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants