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

Gary D. Gregory resolved LANG-1805.
-----------------------------------
    Fix Version/s: 3.20.1
       Resolution: Fixed

Hello [~jher235] 

Thank you for your changes in the PR. These are incomplete. You are only 
covering 2 of the 8 primitive types for the 2 out of the 8 methods you've 
changed. I completed and improved the benchmark. See git master or 
[snapshot|https://repository.apache.org/content/repositories/snapshots/] 
builds. You are credited in {{{}changes.xml{}}}. I've also made the buffer 
allocation for all methods consistent. I believe the PR can be closed.

> Optimize StringBuilder sizing in primitive join methods
> -------------------------------------------------------
>
>                 Key: LANG-1805
>                 URL: https://issues.apache.org/jira/browse/LANG-1805
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 3.20.0
>            Reporter: Jaeheon Kim
>            Priority: Minor
>             Fix For: 3.20.1
>
>
> Current `StringUtils.join` methods for primitive types (int, long, double, 
> etc.) utilize the default `new StringBuilder()` constructor, which has a 
> small initial capacity (16). This leads to frequent internal array resizing 
> and copying when joining arrays with many elements.
> Additionally, the current implementation calls `substring()` at the end to 
> remove the trailing delimiter, which creates an unnecessary intermediate 
> String object.
> I propose optimizing this by:
> 1. Pre-allocating `StringBuilder` capacity based on the array length (e.g., 
> `length * 4` for int), similar to the existing optimization in 
> `join(boolean[])`.
> 2. Refactoring the loop logic to handle the delimiter without needing a final 
> `substring()` call.
> I will submit a GitHub Pull Request with these changes.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to