Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit af39851b authored by Siyamed Sinir's avatar Siyamed Sinir
Browse files

Fix StaticLayout.mDirections array size

mLineDirections variable needs to keep a Directions object for each line
of text. Therefore at any time array of line count is required. However
currently mLineDirections is initialized and grown in the size of mLines
array, which makes the size around mColumns*line count.

This CL removes that extra allocation.

Test: Manual test to check if device boots and displays
Test: bit -t CtsTextTestCases:*
Test: bit -t FrameworksCoreTests:android.text.
Test: bit -t FrameworksCoreTests:android.widget.TextViewTest
Test: bit -t FrameworksCoreTests:android.widget.EditorCursorTest
Test: bit -t CtsWidgetTestCases:android.widget.cts.TextViewTest
Test: bit -t CtsWidgetTestCases:android.widget.cts.EditTextTest

Bug: 64038460
Bug: 62889232
Change-Id: If9bda040b98efcf16c3cdcba5bc27667775ce1fc
parent 62944851
Loading
Loading
Loading
Loading
+17 −16
Original line number Diff line number Diff line
@@ -538,8 +538,8 @@ public class StaticLayout extends Layout {
            mEllipsizedWidth = outerwidth;
        }

        mLineDirections = ArrayUtils.newUnpaddedArray(Directions.class, 2 * mColumns);
        mLines = new int[mLineDirections.length];
        mLineDirections = ArrayUtils.newUnpaddedArray(Directions.class, 2);
        mLines  = ArrayUtils.newUnpaddedIntArray(2 * mColumns);
        mMaximumVisibleLineCount = maxLines;

        generate(b, b.mIncludePad, b.mIncludePad);
@@ -551,8 +551,8 @@ public class StaticLayout extends Layout {
        super(text, null, 0, null, 0, 0);

        mColumns = COLUMNS_ELLIPSIZE;
        mLineDirections = ArrayUtils.newUnpaddedArray(Directions.class, 2 * mColumns);
        mLines = new int[mLineDirections.length];
        mLineDirections = ArrayUtils.newUnpaddedArray(Directions.class, 2);
        mLines  = ArrayUtils.newUnpaddedIntArray(2 * mColumns);
    }

    private StaticLayout(Builder b) {
@@ -577,8 +577,8 @@ public class StaticLayout extends Layout {
            mEllipsizedWidth = b.mWidth;
        }

        mLineDirections = ArrayUtils.newUnpaddedArray(Directions.class, 2 * mColumns);
        mLines = new int[mLineDirections.length];
        mLineDirections = ArrayUtils.newUnpaddedArray(Directions.class, 2);
        mLines  = ArrayUtils.newUnpaddedIntArray(2 * mColumns);
        mMaximumVisibleLineCount = b.mMaxLines;

        mLeftIndents = b.mLeftIndents;
@@ -907,24 +907,25 @@ public class StaticLayout extends Layout {
                      float[] widths, int widthStart, TextUtils.TruncateAt ellipsize,
                      float ellipsisWidth, float textWidth,
                      TextPaint paint, boolean moreChars) {
        int j = mLineCount;
        int off = j * mColumns;
        int want = off + mColumns + TOP;
        final int j = mLineCount;
        final int off = j * mColumns;
        final int want = off + mColumns + TOP;
        int[] lines = mLines;

        if (want >= lines.length) {
            Directions[] grow2 = ArrayUtils.newUnpaddedArray(
                    Directions.class, GrowingArrayUtils.growSize(want));
            System.arraycopy(mLineDirections, 0, grow2, 0,
                             mLineDirections.length);
            mLineDirections = grow2;

            int[] grow = new int[grow2.length];
            final int[] grow = ArrayUtils.newUnpaddedIntArray(GrowingArrayUtils.growSize(want));
            System.arraycopy(lines, 0, grow, 0, lines.length);
            mLines = grow;
            lines = grow;
        }

        if (j >= mLineDirections.length) {
            final Directions[] grow = ArrayUtils.newUnpaddedArray(Directions.class,
                    GrowingArrayUtils.growSize(j));
            System.arraycopy(mLineDirections, 0, grow, 0, mLineDirections.length);
            mLineDirections = grow;
        }

        if (chooseHt != null) {
            fm.ascent = above;
            fm.descent = below;