CAMEL-15390: CollectionStringBuilder - Use JDK util methods instead#4085
CAMEL-15390: CollectionStringBuilder - Use JDK util methods instead#4085davsclaus merged 2 commits intoapache:masterfrom zbendhiba:CAMEL-15390
Conversation
| } | ||
| } | ||
| produces = csb.isEmpty() ? null : csb.toString(); | ||
| produces = producesBuilder.toString().isEmpty() ? null : producesBuilder.toString(); |
There was a problem hiding this comment.
I think we can avoid the 2 x toString as that is a costly operation. We can use length method to know if its empty or not. For example if length > 1 (as delimiter is 1) I think. There is a few other places where toString would be called twice like this.
There was a problem hiding this comment.
The length is 0 by the way, the delimiter is not added. If the value is null, the length gets prefix + suffix, which in this case is empty.
bedlaj
left a comment
There was a problem hiding this comment.
As suggested by Claus. This can be optimized a bit by removing duplicate calls to StringJoiner#toString whenever possible. StringJoiner#toString uses StringBuilder#toString internally, which clones whole String. This String is also not interned, it means it is not reused from String pool and every redundant call to toString wastes memory which needs to be garbage-collected, so it is another reason to avoid duplicate toString calls.
|
Ok |
No description provided.