[ 
https://issues.apache.org/jira/browse/LANG-1057?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Sebb updated LANG-1057:
-----------------------
    Description: 
This is a placeholder issue for github PR 
https://github.com/apache/commons-lang/pull/36

Some parts of our code base use StringBuilder for simple string concatenation. 
But if one compare the generated byte code of:

{code:java}
String foo = "str1" + var + "str2"
{code}

with

{code:java}
String foo = StringBuilder().append("str1").append(var).append("str2)
{code}

it become apperent that the first is a bit more efficient. This is, because the 
compiler will generate the following as byte code:

{code:java}
String foo = StringBuilder("str1").append(var).append(str2)
{code}

Furthermore by using simple String concatenation we leave the choice of how to 
concat the strings to compiler implementors, which may make the code more 
efficient when it is compiled on future compilers.

  was:
This is a placeholder issue for github PR 
https://github.com/apache/commons-lang/pull/36

Some parts of our code base use StringBuilder for simple string concatenation. 
But if one compare the generated byte code of:

{code:java}
String foo = "str1" + var + "str2"
{code}

with

{code:java}
String foo = StringBuilder().append("str1").append(var).append("str2)
{code}

it become apperent that the first is a bit more efficient. This is, because the 
compiler will generate the following as byte code:

{code:java}
String foo = StringBuilder("str1").append(var).append(str2)
{code}

Furthermore by using simple String concatenation we leave the choise of how to 
concat the strings to compiler implementors, which may make the code more 
efficient when it is compiled on future compilers.


> Micro optimization: Replace StringBuilder with String concatenation so that 
> the compiler can better optimize the code
> ---------------------------------------------------------------------------------------------------------------------
>
>                 Key: LANG-1057
>                 URL: https://issues.apache.org/jira/browse/LANG-1057
>             Project: Commons Lang
>          Issue Type: Improvement
>            Reporter: Benedikt Ritter
>              Labels: github
>
> This is a placeholder issue for github PR 
> https://github.com/apache/commons-lang/pull/36
> Some parts of our code base use StringBuilder for simple string 
> concatenation. But if one compare the generated byte code of:
> {code:java}
> String foo = "str1" + var + "str2"
> {code}
> with
> {code:java}
> String foo = StringBuilder().append("str1").append(var).append("str2)
> {code}
> it become apperent that the first is a bit more efficient. This is, because 
> the compiler will generate the following as byte code:
> {code:java}
> String foo = StringBuilder("str1").append(var).append(str2)
> {code}
> Furthermore by using simple String concatenation we leave the choice of how 
> to concat the strings to compiler implementors, which may make the code more 
> efficient when it is compiled on future compilers.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to