Loading core/java/android/util/ArraySet.java +64 −52 Original line number Original line Diff line number Diff line Loading @@ -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 * 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. * list; the second entry is a pointer to the int[] hash code array for it. */ */ static Object[] mBaseCache; static Object[] sBaseCache; static int mBaseCacheSize; static int sBaseCacheSize; static Object[] mTwiceBaseCache; static Object[] sTwiceBaseCache; static int mTwiceBaseCacheSize; static int sTwiceBaseCacheSize; final boolean mIdentityHashCode; final boolean mIdentityHashCode; int[] mHashes; int[] mHashes; Loading Loading @@ -154,29 +154,33 @@ public final class ArraySet<E> implements Collection<E>, Set<E> { private void allocArrays(final int size) { private void allocArrays(final int size) { if (size == (BASE_SIZE * 2)) { if (size == (BASE_SIZE * 2)) { synchronized (ArraySet.class) { synchronized (ArraySet.class) { if (mTwiceBaseCache != null) { if (sTwiceBaseCache != null) { final Object[] array = mTwiceBaseCache; final Object[] array = sTwiceBaseCache; mArray = array; mArray = array; mTwiceBaseCache = (Object[])array[0]; sTwiceBaseCache = (Object[]) array[0]; mHashes = (int[]) array[1]; mHashes = (int[]) array[1]; array[0] = array[1] = null; array[0] = array[1] = null; mTwiceBaseCacheSize--; sTwiceBaseCacheSize--; if (DEBUG) Log.d(TAG, "Retrieving 2x cache " + mHashes if (DEBUG) { + " now have " + mTwiceBaseCacheSize + " entries"); Log.d(TAG, "Retrieving 2x cache " + mHashes + " now have " + sTwiceBaseCacheSize + " entries"); } return; return; } } } } } else if (size == BASE_SIZE) { } else if (size == BASE_SIZE) { synchronized (ArraySet.class) { synchronized (ArraySet.class) { if (mBaseCache != null) { if (sBaseCache != null) { final Object[] array = mBaseCache; final Object[] array = sBaseCache; mArray = array; mArray = array; mBaseCache = (Object[])array[0]; sBaseCache = (Object[]) array[0]; mHashes = (int[]) array[1]; mHashes = (int[]) array[1]; array[0] = array[1] = null; array[0] = array[1] = null; mBaseCacheSize--; sBaseCacheSize--; if (DEBUG) Log.d(TAG, "Retrieving 1x cache " + mHashes if (DEBUG) { + " now have " + mBaseCacheSize + " entries"); Log.d(TAG, "Retrieving 1x cache " + mHashes + " now have " + sBaseCacheSize + " entries"); } return; return; } } } } Loading @@ -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) { private static void freeArrays(final int[] hashes, final Object[] array, final int size) { if (hashes.length == (BASE_SIZE * 2)) { if (hashes.length == (BASE_SIZE * 2)) { synchronized (ArraySet.class) { synchronized (ArraySet.class) { if (mTwiceBaseCacheSize < CACHE_SIZE) { if (sTwiceBaseCacheSize < CACHE_SIZE) { array[0] = mTwiceBaseCache; array[0] = sTwiceBaseCache; array[1] = hashes; array[1] = hashes; for (int i = size - 1; i >= 2; i--) { for (int i = size - 1; i >= 2; i--) { array[i] = null; array[i] = null; } } mTwiceBaseCache = array; sTwiceBaseCache = array; mTwiceBaseCacheSize++; sTwiceBaseCacheSize++; if (DEBUG) Log.d(TAG, "Storing 2x cache " + array if (DEBUG) { + " now have " + mTwiceBaseCacheSize + " entries"); Log.d(TAG, "Storing 2x cache " + array + " now have " + sTwiceBaseCacheSize + " entries"); } } } } } } else if (hashes.length == BASE_SIZE) { } else if (hashes.length == BASE_SIZE) { synchronized (ArraySet.class) { synchronized (ArraySet.class) { if (mBaseCacheSize < CACHE_SIZE) { if (sBaseCacheSize < CACHE_SIZE) { array[0] = mBaseCache; array[0] = sBaseCache; array[1] = hashes; array[1] = hashes; for (int i = size - 1; i >= 2; i--) { for (int i = size - 1; i >= 2; i--) { array[i] = null; array[i] = null; } } mBaseCache = array; sBaseCache = array; mBaseCacheSize++; sBaseCacheSize++; if (DEBUG) Log.d(TAG, "Storing 1x cache " + array if (DEBUG) { + " now have " + mBaseCacheSize + " entries"); Log.d(TAG, "Storing 1x cache " + array + " now have " + sBaseCacheSize + " entries"); } } } } } } } Loading Loading @@ -377,8 +385,9 @@ public final class ArraySet<E> implements Collection<E>, Set<E> { } } if (index < mSize) { if (index < mSize) { if (DEBUG) Log.d(TAG, "add: move " + index + "-" + (mSize-index) if (DEBUG) { + " to " + (index+1)); Log.d(TAG, "add: move " + index + "-" + (mSize - index) + " to " + (index + 1)); } System.arraycopy(mHashes, index, mHashes, index + 1, mSize - index); System.arraycopy(mHashes, index, mHashes, index + 1, mSize - index); System.arraycopy(mArray, index, mArray, index + 1, mSize - index); System.arraycopy(mArray, index, mArray, index + 1, mSize - index); } } Loading Loading @@ -488,16 +497,19 @@ public final class ArraySet<E> implements Collection<E>, Set<E> { System.arraycopy(oarray, 0, mArray, 0, index); System.arraycopy(oarray, 0, mArray, 0, index); } } if (index < mSize) { 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); + " to " + index); } System.arraycopy(ohashes, index + 1, mHashes, index, mSize - index); System.arraycopy(ohashes, index + 1, mHashes, index, mSize - index); System.arraycopy(oarray, index + 1, mArray, index, mSize - index); System.arraycopy(oarray, index + 1, mArray, index, mSize - index); } } } else { } else { mSize--; mSize--; if (index < mSize) { if (index < mSize) { if (DEBUG) Log.d(TAG, "remove: move " + (index+1) + "-" + mSize if (DEBUG) { + " to " + index); Log.d(TAG, "remove: move " + (index + 1) + "-" + mSize + " to " + index); } System.arraycopy(mHashes, index + 1, mHashes, index, mSize - index); System.arraycopy(mHashes, index + 1, mHashes, index, mSize - index); System.arraycopy(mArray, index + 1, mArray, index, mSize - index); System.arraycopy(mArray, index + 1, mArray, index, mSize - index); } } Loading Loading @@ -545,8 +557,8 @@ public final class ArraySet<E> implements Collection<E>, Set<E> { @Override @Override public <T> T[] toArray(T[] array) { public <T> T[] toArray(T[] array) { if (array.length < mSize) { if (array.length < mSize) { @SuppressWarnings("unchecked") T[] newArray @SuppressWarnings("unchecked") T[] newArray = = (T[]) Array.newInstance(array.getClass().getComponentType(), mSize); (T[]) Array.newInstance(array.getClass().getComponentType(), mSize); array = newArray; array = newArray; } } System.arraycopy(mArray, 0, array, 0, mSize); System.arraycopy(mArray, 0, array, 0, mSize); Loading Loading
core/java/android/util/ArraySet.java +64 −52 Original line number Original line Diff line number Diff line Loading @@ -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 * 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. * list; the second entry is a pointer to the int[] hash code array for it. */ */ static Object[] mBaseCache; static Object[] sBaseCache; static int mBaseCacheSize; static int sBaseCacheSize; static Object[] mTwiceBaseCache; static Object[] sTwiceBaseCache; static int mTwiceBaseCacheSize; static int sTwiceBaseCacheSize; final boolean mIdentityHashCode; final boolean mIdentityHashCode; int[] mHashes; int[] mHashes; Loading Loading @@ -154,29 +154,33 @@ public final class ArraySet<E> implements Collection<E>, Set<E> { private void allocArrays(final int size) { private void allocArrays(final int size) { if (size == (BASE_SIZE * 2)) { if (size == (BASE_SIZE * 2)) { synchronized (ArraySet.class) { synchronized (ArraySet.class) { if (mTwiceBaseCache != null) { if (sTwiceBaseCache != null) { final Object[] array = mTwiceBaseCache; final Object[] array = sTwiceBaseCache; mArray = array; mArray = array; mTwiceBaseCache = (Object[])array[0]; sTwiceBaseCache = (Object[]) array[0]; mHashes = (int[]) array[1]; mHashes = (int[]) array[1]; array[0] = array[1] = null; array[0] = array[1] = null; mTwiceBaseCacheSize--; sTwiceBaseCacheSize--; if (DEBUG) Log.d(TAG, "Retrieving 2x cache " + mHashes if (DEBUG) { + " now have " + mTwiceBaseCacheSize + " entries"); Log.d(TAG, "Retrieving 2x cache " + mHashes + " now have " + sTwiceBaseCacheSize + " entries"); } return; return; } } } } } else if (size == BASE_SIZE) { } else if (size == BASE_SIZE) { synchronized (ArraySet.class) { synchronized (ArraySet.class) { if (mBaseCache != null) { if (sBaseCache != null) { final Object[] array = mBaseCache; final Object[] array = sBaseCache; mArray = array; mArray = array; mBaseCache = (Object[])array[0]; sBaseCache = (Object[]) array[0]; mHashes = (int[]) array[1]; mHashes = (int[]) array[1]; array[0] = array[1] = null; array[0] = array[1] = null; mBaseCacheSize--; sBaseCacheSize--; if (DEBUG) Log.d(TAG, "Retrieving 1x cache " + mHashes if (DEBUG) { + " now have " + mBaseCacheSize + " entries"); Log.d(TAG, "Retrieving 1x cache " + mHashes + " now have " + sBaseCacheSize + " entries"); } return; return; } } } } Loading @@ -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) { private static void freeArrays(final int[] hashes, final Object[] array, final int size) { if (hashes.length == (BASE_SIZE * 2)) { if (hashes.length == (BASE_SIZE * 2)) { synchronized (ArraySet.class) { synchronized (ArraySet.class) { if (mTwiceBaseCacheSize < CACHE_SIZE) { if (sTwiceBaseCacheSize < CACHE_SIZE) { array[0] = mTwiceBaseCache; array[0] = sTwiceBaseCache; array[1] = hashes; array[1] = hashes; for (int i = size - 1; i >= 2; i--) { for (int i = size - 1; i >= 2; i--) { array[i] = null; array[i] = null; } } mTwiceBaseCache = array; sTwiceBaseCache = array; mTwiceBaseCacheSize++; sTwiceBaseCacheSize++; if (DEBUG) Log.d(TAG, "Storing 2x cache " + array if (DEBUG) { + " now have " + mTwiceBaseCacheSize + " entries"); Log.d(TAG, "Storing 2x cache " + array + " now have " + sTwiceBaseCacheSize + " entries"); } } } } } } else if (hashes.length == BASE_SIZE) { } else if (hashes.length == BASE_SIZE) { synchronized (ArraySet.class) { synchronized (ArraySet.class) { if (mBaseCacheSize < CACHE_SIZE) { if (sBaseCacheSize < CACHE_SIZE) { array[0] = mBaseCache; array[0] = sBaseCache; array[1] = hashes; array[1] = hashes; for (int i = size - 1; i >= 2; i--) { for (int i = size - 1; i >= 2; i--) { array[i] = null; array[i] = null; } } mBaseCache = array; sBaseCache = array; mBaseCacheSize++; sBaseCacheSize++; if (DEBUG) Log.d(TAG, "Storing 1x cache " + array if (DEBUG) { + " now have " + mBaseCacheSize + " entries"); Log.d(TAG, "Storing 1x cache " + array + " now have " + sBaseCacheSize + " entries"); } } } } } } } Loading Loading @@ -377,8 +385,9 @@ public final class ArraySet<E> implements Collection<E>, Set<E> { } } if (index < mSize) { if (index < mSize) { if (DEBUG) Log.d(TAG, "add: move " + index + "-" + (mSize-index) if (DEBUG) { + " to " + (index+1)); Log.d(TAG, "add: move " + index + "-" + (mSize - index) + " to " + (index + 1)); } System.arraycopy(mHashes, index, mHashes, index + 1, mSize - index); System.arraycopy(mHashes, index, mHashes, index + 1, mSize - index); System.arraycopy(mArray, index, mArray, index + 1, mSize - index); System.arraycopy(mArray, index, mArray, index + 1, mSize - index); } } Loading Loading @@ -488,16 +497,19 @@ public final class ArraySet<E> implements Collection<E>, Set<E> { System.arraycopy(oarray, 0, mArray, 0, index); System.arraycopy(oarray, 0, mArray, 0, index); } } if (index < mSize) { 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); + " to " + index); } System.arraycopy(ohashes, index + 1, mHashes, index, mSize - index); System.arraycopy(ohashes, index + 1, mHashes, index, mSize - index); System.arraycopy(oarray, index + 1, mArray, index, mSize - index); System.arraycopy(oarray, index + 1, mArray, index, mSize - index); } } } else { } else { mSize--; mSize--; if (index < mSize) { if (index < mSize) { if (DEBUG) Log.d(TAG, "remove: move " + (index+1) + "-" + mSize if (DEBUG) { + " to " + index); Log.d(TAG, "remove: move " + (index + 1) + "-" + mSize + " to " + index); } System.arraycopy(mHashes, index + 1, mHashes, index, mSize - index); System.arraycopy(mHashes, index + 1, mHashes, index, mSize - index); System.arraycopy(mArray, index + 1, mArray, index, mSize - index); System.arraycopy(mArray, index + 1, mArray, index, mSize - index); } } Loading Loading @@ -545,8 +557,8 @@ public final class ArraySet<E> implements Collection<E>, Set<E> { @Override @Override public <T> T[] toArray(T[] array) { public <T> T[] toArray(T[] array) { if (array.length < mSize) { if (array.length < mSize) { @SuppressWarnings("unchecked") T[] newArray @SuppressWarnings("unchecked") T[] newArray = = (T[]) Array.newInstance(array.getClass().getComponentType(), mSize); (T[]) Array.newInstance(array.getClass().getComponentType(), mSize); array = newArray; array = newArray; } } System.arraycopy(mArray, 0, array, 0, mSize); System.arraycopy(mArray, 0, array, 0, mSize); Loading