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

Commit f2a45b26 authored by Aurimas Liutikas's avatar Aurimas Liutikas
Browse files

Clean up style issues in ArraySet.

Clean up style issues in preparation to copying ArraySet
implementation to support library.

Fixed:
- Missing spaces around operators, casting
- Added curly braces around if statements that span multiple lines
- Renamed static variables to follow sFoo instead of mFoo
- Moved = to the previous line

Bug: 19109652
Change-Id: Id9a985723b158f51811b3cd796613d0e26fd7e61
parent 8e343179
Loading
Loading
Loading
Loading
+64 −52
Original line number Diff line number Diff line
@@ -64,10 +64,10 @@ public final class ArraySet<E> implements Collection<E>, Set<E> {
     * The first entry in the array is a pointer to the next array in the
     * list; the second entry is a pointer to the int[] hash code array for it.
     */
    static Object[] mBaseCache;
    static int mBaseCacheSize;
    static Object[] mTwiceBaseCache;
    static int mTwiceBaseCacheSize;
    static Object[] sBaseCache;
    static int sBaseCacheSize;
    static Object[] sTwiceBaseCache;
    static int sTwiceBaseCacheSize;

    final boolean mIdentityHashCode;
    int[] mHashes;
@@ -154,29 +154,33 @@ public final class ArraySet<E> implements Collection<E>, Set<E> {
    private void allocArrays(final int size) {
        if (size == (BASE_SIZE * 2)) {
            synchronized (ArraySet.class) {
                if (mTwiceBaseCache != null) {
                    final Object[] array = mTwiceBaseCache;
                if (sTwiceBaseCache != null) {
                    final Object[] array = sTwiceBaseCache;
                    mArray = array;
                    mTwiceBaseCache = (Object[])array[0];
                    sTwiceBaseCache = (Object[]) array[0];
                    mHashes = (int[]) array[1];
                    array[0] = array[1] = null;
                    mTwiceBaseCacheSize--;
                    if (DEBUG) Log.d(TAG, "Retrieving 2x cache " + mHashes
                            + " now have " + mTwiceBaseCacheSize + " entries");
                    sTwiceBaseCacheSize--;
                    if (DEBUG) {
                        Log.d(TAG, "Retrieving 2x cache " + mHashes + " now have "
                                + sTwiceBaseCacheSize + " entries");
                    }
                    return;
                }
            }
        } else if (size == BASE_SIZE) {
            synchronized (ArraySet.class) {
                if (mBaseCache != null) {
                    final Object[] array = mBaseCache;
                if (sBaseCache != null) {
                    final Object[] array = sBaseCache;
                    mArray = array;
                    mBaseCache = (Object[])array[0];
                    sBaseCache = (Object[]) array[0];
                    mHashes = (int[]) array[1];
                    array[0] = array[1] = null;
                    mBaseCacheSize--;
                    if (DEBUG) Log.d(TAG, "Retrieving 1x cache " + mHashes
                            + " now have " + mBaseCacheSize + " entries");
                    sBaseCacheSize--;
                    if (DEBUG) {
                        Log.d(TAG, "Retrieving 1x cache " + mHashes + " now have " + sBaseCacheSize
                                + " entries");
                    }
                    return;
                }
            }
@@ -189,30 +193,34 @@ public final class ArraySet<E> implements Collection<E>, Set<E> {
    private static void freeArrays(final int[] hashes, final Object[] array, final int size) {
        if (hashes.length == (BASE_SIZE * 2)) {
            synchronized (ArraySet.class) {
                if (mTwiceBaseCacheSize < CACHE_SIZE) {
                    array[0] = mTwiceBaseCache;
                if (sTwiceBaseCacheSize < CACHE_SIZE) {
                    array[0] = sTwiceBaseCache;
                    array[1] = hashes;
                    for (int i = size - 1; i >= 2; i--) {
                        array[i] = null;
                    }
                    mTwiceBaseCache = array;
                    mTwiceBaseCacheSize++;
                    if (DEBUG) Log.d(TAG, "Storing 2x cache " + array
                            + " now have " + mTwiceBaseCacheSize + " entries");
                    sTwiceBaseCache = array;
                    sTwiceBaseCacheSize++;
                    if (DEBUG) {
                        Log.d(TAG, "Storing 2x cache " + array + " now have " + sTwiceBaseCacheSize
                                + " entries");
                    }
                }
            }
        } else if (hashes.length == BASE_SIZE) {
            synchronized (ArraySet.class) {
                if (mBaseCacheSize < CACHE_SIZE) {
                    array[0] = mBaseCache;
                if (sBaseCacheSize < CACHE_SIZE) {
                    array[0] = sBaseCache;
                    array[1] = hashes;
                    for (int i = size - 1; i >= 2; i--) {
                        array[i] = null;
                    }
                    mBaseCache = array;
                    mBaseCacheSize++;
                    if (DEBUG) Log.d(TAG, "Storing 1x cache " + array
                            + " now have " + mBaseCacheSize + " entries");
                    sBaseCache = array;
                    sBaseCacheSize++;
                    if (DEBUG) {
                        Log.d(TAG, "Storing 1x cache " + array + " now have "
                                + sBaseCacheSize + " entries");
                    }
                }
            }
        }
@@ -377,8 +385,9 @@ public final class ArraySet<E> implements Collection<E>, Set<E> {
        }

        if (index < mSize) {
            if (DEBUG) Log.d(TAG, "add: move " + index + "-" + (mSize-index)
                    + " to " + (index+1));
            if (DEBUG) {
                Log.d(TAG, "add: move " + index + "-" + (mSize - index) + " to " + (index + 1));
            }
            System.arraycopy(mHashes, index, mHashes, index + 1, mSize - index);
            System.arraycopy(mArray, index, mArray, index + 1, mSize - index);
        }
@@ -488,16 +497,19 @@ public final class ArraySet<E> implements Collection<E>, Set<E> {
                    System.arraycopy(oarray, 0, mArray, 0, index);
                }
                if (index < mSize) {
                    if (DEBUG) Log.d(TAG, "remove: copy from " + (index+1) + "-" + mSize
                    if (DEBUG) {
                        Log.d(TAG, "remove: copy from " + (index + 1) + "-" + mSize
                                + " to " + index);
                    }
                    System.arraycopy(ohashes, index + 1, mHashes, index, mSize - index);
                    System.arraycopy(oarray, index + 1, mArray, index, mSize - index);
                }
            } else {
                mSize--;
                if (index < mSize) {
                    if (DEBUG) Log.d(TAG, "remove: move " + (index+1) + "-" + mSize
                            + " to " + index);
                    if (DEBUG) {
                        Log.d(TAG, "remove: move " + (index + 1) + "-" + mSize + " to " + index);
                    }
                    System.arraycopy(mHashes, index + 1, mHashes, index, mSize - index);
                    System.arraycopy(mArray, index + 1, mArray, index, mSize - index);
                }
@@ -545,8 +557,8 @@ public final class ArraySet<E> implements Collection<E>, Set<E> {
    @Override
    public <T> T[] toArray(T[] array) {
        if (array.length < mSize) {
            @SuppressWarnings("unchecked") T[] newArray
                = (T[]) Array.newInstance(array.getClass().getComponentType(), mSize);
            @SuppressWarnings("unchecked") T[] newArray =
                    (T[]) Array.newInstance(array.getClass().getComponentType(), mSize);
            array = newArray;
        }
        System.arraycopy(mArray, 0, array, 0, mSize);