Jaeheon Kim created LANG-1805:
---------------------------------
Summary: 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
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)