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

Commit c6a65dfb authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "Reduce instructions required to obtain and recycle TypedArray" into lmp-dev

parents 9e348553 8b5b25b4
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.content.res;

import android.util.Pools.SynchronizedPool;
import android.view.ViewDebug;
import com.android.internal.util.XmlUtils;

@@ -96,6 +97,9 @@ public class Resources {
    private static final LongSparseArray<ColorStateList> sPreloadedColorStateLists
            = new LongSparseArray<ColorStateList>();

    // Pool of TypedArrays targeted to this Resources object.
    final SynchronizedPool<TypedArray> mTypedArrayPool = new SynchronizedPool<TypedArray>(5);

    // Used by BridgeResources in layoutlib
    static Resources mSystem = null;

@@ -121,9 +125,10 @@ public class Resources {
    private final int[] mCachedXmlBlockIds = { 0, 0, 0, 0 };
    private final XmlBlock[] mCachedXmlBlocks = new XmlBlock[4];

    private final AssetManager mAssets;
    final AssetManager mAssets;
    final DisplayMetrics mMetrics = new DisplayMetrics();

    private final Configuration mConfiguration = new Configuration();
    private final DisplayMetrics mMetrics = new DisplayMetrics();
    private NativePluralRules mPluralRule;

    private CompatibilityInfo mCompatibilityInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
+8 −17
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.Pools.SynchronizedPool;
import android.util.TypedValue;

import com.android.internal.util.XmlUtils;
@@ -37,15 +36,11 @@ import java.util.Arrays;
 * the positions of the attributes given to obtainStyledAttributes.
 */
public class TypedArray {
    private static final SynchronizedPool<TypedArray> mPool = new SynchronizedPool<TypedArray>(5);

    static TypedArray obtain(Resources res, int len) {
        final TypedArray attrs = mPool.acquire();
        final TypedArray attrs = res.mTypedArrayPool.acquire();
        if (attrs != null) {
            attrs.mLength = len;
            attrs.mResources = res;
            attrs.mMetrics = res.getDisplayMetrics();
            attrs.mAssets = res.getAssets();
            attrs.mRecycled = false;

            final int fullLen = len * AssetManager.STYLE_NUM_ENTRIES;
@@ -63,9 +58,10 @@ public class TypedArray {
                new int[1+len], len);
    }

    private Resources mResources;
    private DisplayMetrics mMetrics;
    private AssetManager mAssets;
    private final Resources mResources;
    private final DisplayMetrics mMetrics;
    private final AssetManager mAssets;

    private boolean mRecycled;

    /*package*/ XmlBlock.Parser mXml;
@@ -872,17 +868,12 @@ public class TypedArray {
        }

        mRecycled = true;
        mResources = null;
        mMetrics = null;
        mAssets = null;

        // These may have been set by the client.
        mXml = null;
        mTheme = null;

        synchronized (mPool) {
            mPool.release(this);
        }
        mResources.mTypedArrayPool.release(this);
    }

    /**
@@ -984,8 +975,8 @@ public class TypedArray {

    /*package*/ TypedArray(Resources resources, int[] data, int[] indices, int len) {
        mResources = resources;
        mMetrics = mResources.getDisplayMetrics();
        mAssets = mResources.getAssets();
        mMetrics = mResources.mMetrics;
        mAssets = mResources.mAssets;
        mData = data;
        mIndices = indices;
        mLength = len;