You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary Gregory (JIRA)" <ji...@apache.org> on 2017/11/10 19:28:00 UTC

[jira] [Updated] (LANG-1367) ObjectUtils.identityToString(Object) and friends should allocate builders and buffers with a size

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

Gary Gregory updated LANG-1367:
-------------------------------
    Description: 
The method {{ObjectUtils.identityToString(Object)}} and its friends should allocate builders and buffers with a size.

Calling {{ObjectUtils.identityToString(Object)}} will allocate a {{StringBuilder}} and append to it. The {{StringBuilder}} will reallocate it's internal {{char[]}} at least once since most strings end up being larger than the default 16 characters initially allocated by a StringBuilder (on Oracle Java 7).

This change computes the strings parts first and then allocates a {{StringBuilder}} of the right size.

Similarly, the {{identityToString}} methods that accept an existing builder/buffer can call {{ensureCapacity}} to avoid any extraneous allocations.


  was:
ObjectUtils.identityToString(Object) and friends should allocate builders and buffers with a size.

Calling ObjectUtils.identityToString(Object) will allocate a {{StringBuilder}} and append to it. The {{StringBuilder}} will reallocate it's internal {{char[]}} at least once since most strings end up being larger than the default 16 characters initially allocated by a StringBuilder (on Oracle Java 7).

This change computes the strings parts first and then allocates a {{StringBuilder}} of the right size.

Similarly, the {{identityToString}} methods that accept an existing builder/buffer can call {{ensureCapacity}} to avoid any extraneous allocations.



> ObjectUtils.identityToString(Object) and friends should allocate builders and buffers with a size
> -------------------------------------------------------------------------------------------------
>
>                 Key: LANG-1367
>                 URL: https://issues.apache.org/jira/browse/LANG-1367
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>            Reporter: Gary Gregory
>            Assignee: Gary Gregory
>             Fix For: 3.8
>
>
> The method {{ObjectUtils.identityToString(Object)}} and its friends should allocate builders and buffers with a size.
> Calling {{ObjectUtils.identityToString(Object)}} will allocate a {{StringBuilder}} and append to it. The {{StringBuilder}} will reallocate it's internal {{char[]}} at least once since most strings end up being larger than the default 16 characters initially allocated by a StringBuilder (on Oracle Java 7).
> This change computes the strings parts first and then allocates a {{StringBuilder}} of the right size.
> Similarly, the {{identityToString}} methods that accept an existing builder/buffer can call {{ensureCapacity}} to avoid any extraneous allocations.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)