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

Commit ad187366 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[res] Preserve the resid order in ThemeKey"

parents 1728e088 358ea565
Loading
Loading
Loading
Loading
+25 −11
Original line number Diff line number Diff line
@@ -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,16 +2034,18 @@ 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);
            }
        }

        /**
         * Sets up this key as a deep copy of another key.