RFR: 8344668: Unnecessary array allocations and copying in TextLine
Daniel Gredler
dgredler at openjdk.org
Thu Nov 21 00:25:26 UTC 2024
When `LineBreakMeasurer` is used to break text into lines, internally it uses `TextMeasurer` and `TextLine` to do the job. In the common case, `TextLine.getComponents(...)` allocates a `TextLineComponent[]` with room for a single array entry, and passes it to `TextLine.createComponentsOnRun(...)`, which fills the array and returns it, optionally resizing to a larger array if necessary, after which the array is resized back down to actual size (if necessary).
Unfortunately `TextLine.createComponentsOnRun(...)` is too eager in allocating larger arrays. In the most common case of a single component, this means that a single-element array is allocated, then a 9-element array is allocated (via `expandArray(...)`), and then another single-element array is allocated (to shrink the array back to actual size). Only one array allocation is necessary in this common case, and no array copying is needed.
-------------
Commit messages:
- Avoid unnecessary array allocations and copying in TextLine
Changes: https://git.openjdk.org/jdk/pull/22288/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=22288&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8344668
Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
Patch: https://git.openjdk.org/jdk/pull/22288.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/22288/head:pull/22288
PR: https://git.openjdk.org/jdk/pull/22288
More information about the client-libs-dev
mailing list