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

Commit f0ec2dd3 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "Fix problems where we were allocating TypedArray when not needed."

parents 8a6d7323 ab0f485e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -915,6 +915,7 @@ public abstract class ActionBar {
                    com.android.internal.R.styleable.ActionBar_LayoutParams);
            gravity = a.getInt(
                    com.android.internal.R.styleable.ActionBar_LayoutParams_layout_gravity, -1);
            a.recycle();
        }

        public LayoutParams(int width, int height) {
+15 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ public class Resources {
    static final String TAG = "Resources";
    private static final boolean DEBUG_LOAD = false;
    private static final boolean DEBUG_CONFIG = false;
    private static final boolean DEBUG_ATTRIBUTES_CACHE = false;
    private static final boolean TRACE_FOR_PRELOAD = false;
    private static final boolean TRACE_FOR_MISS_PRELOAD = false;

@@ -104,6 +105,7 @@ public class Resources {
    private boolean mPreloading;

    /*package*/ TypedArray mCachedStyledAttributes = null;
    RuntimeException mLastRetrievedAttrs = null;

    private int mLastCachedXmlBlockIndex = -1;
    private final int[] mCachedXmlBlockIds = { 0, 0, 0, 0 };
@@ -2167,6 +2169,10 @@ public class Resources {
            TypedArray attrs = mCachedStyledAttributes;
            if (attrs != null) {
                mCachedStyledAttributes = null;
                if (DEBUG_ATTRIBUTES_CACHE) {
                    mLastRetrievedAttrs = new RuntimeException("here");
                    mLastRetrievedAttrs.fillInStackTrace();
                }

                attrs.mLength = len;
                int fullLen = len * AssetManager.STYLE_NUM_ENTRIES;
@@ -2177,6 +2183,15 @@ public class Resources {
                attrs.mIndices = new int[1+len];
                return attrs;
            }
            if (DEBUG_ATTRIBUTES_CACHE) {
                RuntimeException here = new RuntimeException("here");
                here.fillInStackTrace();
                if (mLastRetrievedAttrs != null) {
                    Log.i(TAG, "Allocated new TypedArray of " + len + " in " + this, here);
                    Log.i(TAG, "Last retrieved attributes here", mLastRetrievedAttrs);
                }
                mLastRetrievedAttrs = here;
            }
            return new TypedArray(this,
                    new int[len*AssetManager.STYLE_NUM_ENTRIES],
                    new int[1+len], len);
+5 −5
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import android.graphics.Canvas;
import android.graphics.Interpolator;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Matrix.ScaleToFit;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Point;
@@ -2272,8 +2271,6 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
     */
    int mOldHeightMeasureSpec = Integer.MIN_VALUE;
    private Resources mResources = null;
    private Drawable mBGDrawable;
    private int mBackgroundResource;
@@ -2336,6 +2333,8 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
     */
    protected Context mContext;
    private final Resources mResources;
    private ScrollabilityCache mScrollCache;
    private int[] mDrawableState = null;
@@ -3017,6 +3016,8 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
            }
        }
        a.recycle();
        setOverScrollMode(overScrollMode);
        if (background != null) {
@@ -3074,14 +3075,13 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
        }
        computeOpaqueFlags();
        a.recycle();
    }
    /**
     * Non-public constructor for use in testing
     */
    View() {
        mResources = null;
    }
    /**
+8 −7
Original line number Diff line number Diff line
@@ -232,11 +232,6 @@ public abstract class Animation implements Cloneable {
        setFillBefore(a.getBoolean(com.android.internal.R.styleable.Animation_fillBefore, mFillBefore));
        setFillAfter(a.getBoolean(com.android.internal.R.styleable.Animation_fillAfter, mFillAfter));

        final int resID = a.getResourceId(com.android.internal.R.styleable.Animation_interpolator, 0);
        if (resID > 0) {
            setInterpolator(context, resID);
        }

        setRepeatCount(a.getInt(com.android.internal.R.styleable.Animation_repeatCount, mRepeatCount));
        setRepeatMode(a.getInt(com.android.internal.R.styleable.Animation_repeatMode, RESTART));

@@ -246,9 +241,15 @@ public abstract class Animation implements Cloneable {

        setDetachWallpaper(a.getBoolean(com.android.internal.R.styleable.Animation_detachWallpaper, false));

        ensureInterpolator();
        final int resID = a.getResourceId(com.android.internal.R.styleable.Animation_interpolator, 0);

        a.recycle();

        if (resID > 0) {
            setInterpolator(context, resID);
        }

        ensureInterpolator();
    }

    @Override
+12 −8
Original line number Diff line number Diff line
@@ -461,10 +461,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        mMovement = getDefaultMovementMethod();
        mTransformation = null;

        TypedArray a =
            context.obtainStyledAttributes(
                attrs, com.android.internal.R.styleable.TextView, defStyle, 0);

        int textColorHighlight = 0;
        ColorStateList textColor = null;
        ColorStateList textColorHint = null;
@@ -474,18 +470,23 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        int styleIndex = -1;
        boolean allCaps = false;

        final Resources.Theme theme = context.getTheme();

        /*
         * Look the appearance up without checking first if it exists because
         * almost every TextView has one and it greatly simplifies the logic
         * to be able to parse the appearance first and then let specific tags
         * for this View override it.
         */
        TypedArray a = theme.obtainStyledAttributes(
                    attrs, com.android.internal.R.styleable.TextViewAppearance, defStyle, 0);
        TypedArray appearance = null;
        int ap = a.getResourceId(com.android.internal.R.styleable.TextView_textAppearance, -1);
        int ap = a.getResourceId(
                com.android.internal.R.styleable.TextViewAppearance_textAppearance, -1);
        a.recycle();
        if (ap != -1) {
            appearance = context.obtainStyledAttributes(ap,
                                com.android.internal.R.styleable.
                                TextAppearance);
            appearance = theme.obtainStyledAttributes(
                    ap, com.android.internal.R.styleable.TextAppearance);
        }
        if (appearance != null) {
            int n = appearance.getIndexCount();
@@ -552,6 +553,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        boolean password = false;
        int inputType = EditorInfo.TYPE_NULL;

        a = theme.obtainStyledAttributes(
                    attrs, com.android.internal.R.styleable.TextView, defStyle, 0);

        int n = a.getIndexCount();
        for (int i = 0; i < n; i++) {
            int attr = a.getIndex(i);
Loading