diff options
| author | 2023-06-23 19:19:12 +0000 | |
|---|---|---|
| committer | 2023-06-23 19:19:12 +0000 | |
| commit | bf99a6ac5626209c9ef5bd86a6d74c5e223ac61c (patch) | |
| tree | d6de6cd685f46c0e83de31894d20160d72624141 | |
| parent | bedae25d0ead4b3bcdb360c1ed0490cc603ba65b (diff) | |
| parent | f57406f61a238fa5383a653a0b030e548c8a7e45 (diff) | |
Merge "[res] Preserve the resid order in ThemeKey" into udc-dev am: 375d648950 am: f57406f61a
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23755569
Change-Id: Id0fc1ae5222881a1595aeb237279638d68451f70
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | core/java/android/content/res/Resources.java | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java index 885060f19efa..c3d5b71e7349 100644 --- a/core/java/android/content/res/Resources.java +++ b/core/java/android/content/res/Resources.java @@ -2003,13 +2003,25 @@ public class Resources { private int mHashCode = 0; - private boolean containsValue(int resId, boolean force) { + private int findValue(int resId, boolean force) { for (int i = 0; i < mCount; ++i) { if (mResId[i] == resId && mForce[i] == force) { - return true; + return i; } } - return false; + return -1; + } + + private void moveToLast(int index) { + if (index < 0 || index >= mCount - 1) { + return; + } + final int id = mResId[index]; + final boolean force = mForce[index]; + System.arraycopy(mResId, index + 1, mResId, index, mCount - index - 1); + mResId[mCount - 1] = id; + System.arraycopy(mForce, index + 1, mForce, index, mCount - index - 1); + mForce[mCount - 1] = force; } public void append(int resId, boolean force) { @@ -2022,15 +2034,17 @@ public class Resources { } // Some apps tend to keep adding same resources over and over, let's protect from it. - if (containsValue(resId, force)) { - return; + // Note: the order still matters, as the values that come later override the earlier + // ones. + final int index = findValue(resId, force); + if (index >= 0) { + moveToLast(index); + } else { + mResId = GrowingArrayUtils.append(mResId, mCount, resId); + mForce = GrowingArrayUtils.append(mForce, mCount, force); + mCount++; + mHashCode = 31 * (31 * mHashCode + resId) + (force ? 1 : 0); } - - mResId = GrowingArrayUtils.append(mResId, mCount, resId); - mForce = GrowingArrayUtils.append(mForce, mCount, force); - mCount++; - - mHashCode = 31 * (31 * mHashCode + resId) + (force ? 1 : 0); } /** |