jher235 opened a new pull request, #1532:
URL: https://github.com/apache/commons-lang/pull/1532
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
### Description
This pull request improves the internal implementation of the primitive
`join` methods by reducing unnecessary `StringBuilder` resizing and
aligning capacity calculations with the actual join range.
The changes are limited to implementation details and do not alter
public behavior or output.
### Changes
1. **Capacity Pre-sizing**
- Initialize `StringBuilder` with an estimated capacity based on the
number of elements being joined (`endIndex - startIndex`).
- This avoids repeated buffer growth when appending numeric values
and reduces allocation and copy overhead.
2. **Capacity Calculation Alignment**
- Updated capacity calculations in `join(char[])`, `join(byte[])`,
and `join(short[])` to consistently use the join range
(`endIndex - startIndex`) instead of the full array length.
- This avoids over-allocating internal buffers when joining
sub-ranges of large arrays.
3. **Minor Loop Refactoring**
- Adjusted delimiter handling inside the loop to avoid trimming the
final delimiter via `substring()`, keeping the resulting behavior
unchanged while simplifying the control flow.
### Jira Ticket
https://issues.apache.org/jira/browse/LANG-1805
### Checklist
- [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
- [x] Read the [ASF Generative Tooling
Guidance](https://www.apache.org/legal/generative-tooling.html) if you use
Artificial Intelligence (AI).
- [x] I used AI tools for discussion, idea validation and drafting messages
all code and changes were written, reviewed, and verified by me.
- [x] Run a successful build using the default
[Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command
line by itself.
- [x] Ran a successful build using the default Maven goal (`mvn clean
verify`).
- [x] Existing tests pass; no behavioral changes were introduced.
- [x] Commits have meaningful and focused subject lines.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]