From 10979613899ca3963c7d64d25d5f8ef7db1dde84 Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Wed, 6 Jan 2016 15:27:35 -0500 Subject: [PATCH] Cache XML blocks against file name rather than resource ID Caching against resource ID leads to incorrect cache hits, since multiple files (ex. within drawable-mdpi, drawable-ldpi) may map to the same ID. Also adds nullability annotations. Bug: 26400880 Change-Id: I4d83caf3c44dc9b546511753e9e72171e8850eb2 --- core/java/android/content/res/Resources.java | 84 ++++++++++++-------- 1 file changed, 50 insertions(+), 34 deletions(-) diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java index 60c6e825e1be4..e9c1d0886cfc5 100644 --- a/core/java/android/content/res/Resources.java +++ b/core/java/android/content/res/Resources.java @@ -151,8 +151,9 @@ public class Resources { private boolean mPreloading; + // Cyclical cache used for recently-accessed XML files. private int mLastCachedXmlBlockIndex = -1; - private final int[] mCachedXmlBlockIds = { 0, 0, 0, 0 }; + private final String[] mCachedXmlBlockFiles = new String[4]; private final XmlBlock[] mCachedXmlBlocks = new XmlBlock[4]; final AssetManager mAssets; @@ -2351,16 +2352,17 @@ public class Resources { * tools. */ public final void flushLayoutCache() { - synchronized (mCachedXmlBlockIds) { - // First see if this block is in our cache. - final int num = mCachedXmlBlockIds.length; - for (int i=0; i