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

Commit f7fd0088 authored by Adam Lesinski's avatar Adam Lesinski Committed by Android (Google) Code Review
Browse files

Merge "Uses VMRuntime.newUnpaddedArray for ideal array sizes"

parents 1c14c327 776abc24
Loading
Loading
Loading
Loading
+5 −18
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.content.res;
import android.graphics.Color;

import com.android.internal.util.ArrayUtils;
import com.android.internal.util.GrowingArrayUtils;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -181,10 +182,9 @@ public class ColorStateList implements Parcelable {
        final int innerDepth = parser.getDepth()+1;
        int depth;

        int listAllocated = 20;
        int[][] stateSpecList = ArrayUtils.newUnpaddedArray(int[].class, 20);
        int[] colorList = new int[stateSpecList.length];
        int listSize = 0;
        int[] colorList = new int[listAllocated];
        int[][] stateSpecList = new int[listAllocated][];

        while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
               && ((depth=parser.getDepth()) >= innerDepth
@@ -248,21 +248,8 @@ public class ColorStateList implements Parcelable {
                mDefaultColor = color;
            }

            if (listSize + 1 >= listAllocated) {
                listAllocated = ArrayUtils.idealIntArraySize(listSize + 1);

                int[] ncolor = new int[listAllocated];
                System.arraycopy(colorList, 0, ncolor, 0, listSize);

                int[][] nstate = new int[listAllocated][];
                System.arraycopy(stateSpecList, 0, nstate, 0, listSize);

                colorList = ncolor;
                stateSpecList = nstate;
            }

            colorList[listSize] = color;
            stateSpecList[listSize] = stateSpec;
            colorList = GrowingArrayUtils.append(colorList, listSize, color);
            stateSpecList = GrowingArrayUtils.append(stateSpecList, listSize, stateSpec);
            listSize++;
        }

+6 −11
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.text.style.UpdateLayout;
import android.text.style.WrapTogetherSpan;

import com.android.internal.util.ArrayUtils;
import com.android.internal.util.GrowingArrayUtils;

import java.lang.ref.WeakReference;

@@ -401,7 +402,7 @@ public class DynamicLayout extends Layout

        if (mBlockEndLines == null) {
            // Initial creation of the array, no test on previous block ending line
            mBlockEndLines = new int[ArrayUtils.idealIntArraySize(1)];
            mBlockEndLines = ArrayUtils.newUnpaddedIntArray(1);
            mBlockEndLines[mNumberOfBlocks] = line;
            mNumberOfBlocks++;
            return;
@@ -409,13 +410,7 @@ public class DynamicLayout extends Layout

        final int previousBlockEndLine = mBlockEndLines[mNumberOfBlocks - 1];
        if (line > previousBlockEndLine) {
            if (mNumberOfBlocks == mBlockEndLines.length) {
                // Grow the array if needed
                int[] blockEndLines = new int[ArrayUtils.idealIntArraySize(mNumberOfBlocks + 1)];
                System.arraycopy(mBlockEndLines, 0, blockEndLines, 0, mNumberOfBlocks);
                mBlockEndLines = blockEndLines;
            }
            mBlockEndLines[mNumberOfBlocks] = line;
            mBlockEndLines = GrowingArrayUtils.append(mBlockEndLines, mNumberOfBlocks, line);
            mNumberOfBlocks++;
        }
    }
@@ -483,9 +478,9 @@ public class DynamicLayout extends Layout
        }

        if (newNumberOfBlocks > mBlockEndLines.length) {
            final int newSize = ArrayUtils.idealIntArraySize(newNumberOfBlocks);
            int[] blockEndLines = new int[newSize];
            int[] blockIndices = new int[newSize];
            int[] blockEndLines = ArrayUtils.newUnpaddedIntArray(
                    Math.max(mBlockEndLines.length * 2, newNumberOfBlocks));
            int[] blockIndices = new int[blockEndLines.length];
            System.arraycopy(mBlockEndLines, 0, blockEndLines, 0, firstBlock);
            System.arraycopy(mBlockIndices, 0, blockIndices, 0, firstBlock);
            System.arraycopy(mBlockEndLines, lastBlock + 1,
+1 −1
Original line number Diff line number Diff line
@@ -211,7 +211,7 @@ public class Html {

    private static String getOpenParaTagWithDirection(Spanned text, int start, int end) {
        final int len = end - start;
        final byte[] levels = new byte[ArrayUtils.idealByteArraySize(len)];
        final byte[] levels = ArrayUtils.newUnpaddedByteArray(len);
        final char[] buffer = TextUtils.obtain(len);
        TextUtils.getChars(text, start, end, buffer, 0);

+4 −8
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.text.style.ReplacementSpan;
import android.text.style.TabStopSpan;

import com.android.internal.util.ArrayUtils;
import com.android.internal.util.GrowingArrayUtils;

import java.util.Arrays;

@@ -403,14 +404,9 @@ public abstract class Layout {
                                // construction
                                if (mLineBackgroundSpans.spanStarts[j] >= end ||
                                        mLineBackgroundSpans.spanEnds[j] <= start) continue;
                                if (spansLength == spans.length) {
                                    // The spans array needs to be expanded
                                    int newSize = ArrayUtils.idealObjectArraySize(2 * spansLength);
                                    ParagraphStyle[] newSpans = new ParagraphStyle[newSize];
                                    System.arraycopy(spans, 0, newSpans, 0, spansLength);
                                    spans = newSpans;
                                }
                                spans[spansLength++] = mLineBackgroundSpans.spans[j];
                                spans = GrowingArrayUtils.append(
                                        spans, spansLength, mLineBackgroundSpans.spans[j]);
                                spansLength++;
                            }
                        }
                    }
+3 −3
Original line number Diff line number Diff line
@@ -98,10 +98,10 @@ class MeasuredText {
        mPos = 0;

        if (mWidths == null || mWidths.length < len) {
            mWidths = new float[ArrayUtils.idealFloatArraySize(len)];
            mWidths = ArrayUtils.newUnpaddedFloatArray(len);
        }
        if (mChars == null || mChars.length < len) {
            mChars = new char[ArrayUtils.idealCharArraySize(len)];
            mChars = ArrayUtils.newUnpaddedCharArray(len);
        }
        TextUtils.getChars(text, start, end, mChars, 0);

@@ -130,7 +130,7 @@ class MeasuredText {
            mEasy = true;
        } else {
            if (mLevels == null || mLevels.length < len) {
                mLevels = new byte[ArrayUtils.idealByteArraySize(len)];
                mLevels = ArrayUtils.newUnpaddedByteArray(len);
            }
            int bidiRequest;
            if (textDir == TextDirectionHeuristics.LTR) {
Loading