Skip to content

Fix the problem of using '+' and '+=' operators to concatenate strings in a loop. - #2016

Closed
Kui-Liu wants to merge 2 commits into
apache:masterfrom
Kui-Liu:master
Closed

Kui-Liu wants to merge 2 commits into
apache:masterfrom
Kui-Liu:master

Conversation

@Kui-Liu

@Kui-Liu Kui-Liu commented Oct 9, 2017 •

Copy link
Copy Markdown
Contributor

The method is building a String using concatenation in a loop.
In each iteration, the String is converted to a StringBuilder, appended to, and converted back to a String.
This can lead to a cost quadratic in the number of iterations, as the growing string is recopied in each iteration.
Better performance can be obtained by using a StringBuilder explicitly.
http://findbugs.sourceforge.net/bugDescriptions.html#SBSC_USE_STRINGBUFFER_CONCATENATION

…s in a loop.

The method is building a String using concatenation in a loop.
In each iteration, the String is converted to a StringBuilder, appended to, and converted back to a String.
This can lead to a cost quadratic in the number of iterations, as the growing string is recopied in each iteration.
Better performance can be obtained by using a StringBuilder explicitly.
http://findbugs.sourceforge.net/bugDescriptions.html#SBSC_USE_STRINGBUFFER_CONCATENATION
@oscerd

oscerd commented Oct 11, 2017

Copy link
Copy Markdown
Contributor

I'm gonna merge this

@davsclaus

Copy link
Copy Markdown
Contributor

@oscerd oh I just merged

There is a build error in this example, I wonder if you could take a look

[ERROR] /Users/davsclaus/workspace/camel/examples/camel-example-cdi-kubernetes/src/main/java/org/apache/camel/example/cdi/kubernetes/Application.java:[71,108] error: incompatible types: Time cannot be converted to CharSequence

@davsclaus

Copy link
Copy Markdown
Contributor

Thanks for the PR it has been merged. Do you mind closing this?

@Kui-Liu

Kui-Liu commented Oct 11, 2017

Copy link
Copy Markdown
Contributor Author

Thanks.

@Kui-Liu Kui-Liu closed this Oct 11, 2017
@oscerd

oscerd commented Oct 11, 2017

Copy link
Copy Markdown
Contributor

@davsclaus I'll take a look :-)

@oscerd

oscerd commented Oct 11, 2017

Copy link
Copy Markdown
Contributor

@davsclaus I can't reproduce the error on my side. Not sure why.

…a in a loop.

The method is building a String using concatenation in a loop.
In each iteration, the String is converted to a StringBuilder, appended to, and converted back to a String.
This can lead to a cost quadratic in the number of iterations, as the growing string is recopied in each iteration.
Better performance can be obtained by using a StringBuilder explicitly.
http://findbugs.sourceforge.net/bugDescriptions.html#SBSC_USE_STRINGBUFFER_CONCATENATION
@Kui-Liu Kui-Liu reopened this Oct 11, 2017
@davsclaus

Copy link
Copy Markdown
Contributor

@brucekuiliu you need to create a new PR you cannot reopen old ones that has been merged.

@Kui-Liu

Kui-Liu commented Oct 11, 2017

Copy link
Copy Markdown
Contributor Author

I see, many thanks.

@Kui-Liu Kui-Liu closed this Oct 11, 2017
Croway pushed a commit to Croway/camel that referenced this pull request Mar 14, 2024
[ENTESB-18702] Experimental lazy loading of file attributes
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.

3 participants