Merge "Reduce instructions required to obtain and recycle TypedArray" into lmp-dev
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java
index cabe228..7f276c2 100644
--- a/core/java/android/content/res/Resources.java
+++ b/core/java/android/content/res/Resources.java
@@ -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 @@
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 @@
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;
diff --git a/core/java/android/content/res/TypedArray.java b/core/java/android/content/res/TypedArray.java
index 8607bbc..186623a 100644
--- a/core/java/android/content/res/TypedArray.java
+++ b/core/java/android/content/res/TypedArray.java
@@ -20,7 +20,6 @@
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 @@
* 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 @@
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 @@
}
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 @@
/*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;