Skip to content

Conversation

stsypanov
Copy link
Contributor

As it follows from
http://alblue.bandlem.com/2016/04/jmh-stringbuffer-stringbuilder.html
and
https://habr.com/ru/post/330220/
chained StringBuilder::append is much faster than conventional sb.append(); sb.append().

Assyming that expression like String str = str1 + str2 + str3; at runtime will behave as chained StringBuilder::append we can simplify usage of StringBuilder in particular cases like the one of this PR.

Here we have 2 cases:

  • if expression is false
  • if expression is true

In the first case we don't need SB at all, as resulting expression produced by sb.toString() equals this.contentType.
And in the opposite case we have non-interrupted StringBuilder::append chain (later simplifiable to String concatenation with +) and thus more simple code and better performance.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 25, 2019
@jhoeller jhoeller merged commit 1c24dc1 into spring-projects:master Feb 25, 2019
@jhoeller jhoeller self-assigned this Feb 25, 2019
@jhoeller jhoeller added type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 25, 2019
@jhoeller jhoeller added this to the 5.2 M1 milestone Feb 25, 2019
jhoeller added a commit that referenced this pull request Feb 25, 2019
@stsypanov stsypanov deleted the sb-simplification branch February 26, 2019 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: task A general task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants