[
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 part first (class name and hex hash code
string) 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:
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.
> 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 part first (class name and hex hash code
> string) 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)