commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Charles Honton (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (LANG-1057) Micro optimization: Replace StringBuilder with String concatenation so that the compiler can better optimize the code
Date Wed, 15 Jul 2015 04:06:04 GMT

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

Charles Honton resolved LANG-1057.
----------------------------------
       Resolution: Fixed
    Fix Version/s: 3.5

The StringUtils changes were not accepted.  The code pre-allocates proper size for buffer.
 Preventing buffer resizing is probably more than the compiler can figure out.

> 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
>            Assignee: Charles Honton
>              Labels: github
>             Fix For: 3.5
>
>
> 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)

Mime
View raw message