commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LANG-990) Avoid String allocation in StrBuilder.append(CharSequence)
Date Fri, 13 Mar 2015 15:23:40 GMT

    [ https://issues.apache.org/jira/browse/LANG-990?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14360505#comment-14360505
] 

ASF GitHub Bot commented on LANG-990:
-------------------------------------

GitHub user CodingFabian opened a pull request:

    https://github.com/apache/commons-lang/pull/51

    LANG-990 support appending CharBuffer and use specialized methods

    StrBuilder accepts CharSequences as well as specialized instances like
    String, StringBuffer. If you force one of these implementations through generic
    methods, suboptimal code path will be taken.
    This is a problem for any "generic" reuse.
    
    Additionally, it is possible to optimize for CharBuffers which are array backed.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/CodingFabian/commons-lang LANG-990

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/commons-lang/pull/51.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #51
    
----
commit 257d6bffc52e56c95ac89760db57bbc1f7358377
Author: Fabian Lange <lange.fabian@gmail.com>
Date:   2015-03-13T15:19:29Z

    LANG-990 support appending CharBuffer and use specialized methods when possible.
    
    StrBuilder accepts CharSequences as well as specialized instances like
    String, StringBuffer. If you force one of these implementations through generic
    methods, suboptimal code path will be taken.
    This is a problem for any "generic" reuse.
    
    Additionally, it is possible to optimize for CharBuffers which are array backed.

----


> Avoid String allocation in StrBuilder.append(CharSequence)
> ----------------------------------------------------------
>
>                 Key: LANG-990
>                 URL: https://issues.apache.org/jira/browse/LANG-990
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.text.*
>    Affects Versions: 3.3.1
>            Reporter: Mikhail Mazursky
>             Fix For: Patch Needed
>
>         Attachments: LANG-990-v2.patch, LANG-990-v3.patch, LANG-990.patch
>
>
> StrBuilder.append(CharSequence) and StrBuilder.append(CharSequence, int, int) can be
optimized for the case when CharBuffer is passed. Current implementation calls toString()
method that allocates a new String. In case when CharBuffer.hasArray() returns true the buffer-backing
char array can be accessed directly to copy chars from it.
> Also an instanceOf StrBuilder check can be added to StrBuilder.append(CharSequence) and
StrBuilder.append(CharSequence, int, int) to avoid toString() in that case too (StrBuilder
can be passed as CharSequence in some cases).



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

Mime
View raw message