Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8344668

Unnecessary array allocations and copying in TextLine

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P5 P5
    • 25
    • 23
    • client-libs
    • None
    • 2d
    • b02

      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.

            dgredler Daniel Gredler
            dgredler Daniel Gredler
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: