Loading apct-tests/perftests/core/src/android/util/ArraySetPerfTest.java +33 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import java.util.function.Consumer; import java.util.function.Predicate; @RunWith(AndroidJUnit4.class) Loading @@ -38,6 +39,38 @@ public class ArraySetPerfTest { @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); @Test public void testForEach_Small() { BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); Consumer<Integer> consumer = (i) -> { }; while (state.keepRunning()) { for (int i = 0; i < NUM_ITERATIONS; ++i) { ArraySet<Integer> set = new ArraySet<>(); for (int j = 0; j < SET_SIZE_SMALL; j++) { set.add(j); } set.forEach(consumer); } } } @Test public void testForEach_Large() { BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); Consumer<Integer> consumer = (i) -> { }; while (state.keepRunning()) { for (int i = 0; i < NUM_ITERATIONS; ++i) { ArraySet<Integer> set = new ArraySet<>(); for (int j = 0; j < SET_SIZE_LARGE; j++) { set.add(j); } set.forEach(consumer); } } } @Test public void testValueAt_InBounds() { BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); Loading core/api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -45993,6 +45993,7 @@ package android.util { method public boolean contains(Object); method public boolean containsAll(java.util.Collection<?>); method public void ensureCapacity(int); method public void forEach(java.util.function.Consumer<? super E>); method public int indexOf(Object); method public boolean isEmpty(); method public java.util.Iterator<E> iterator(); core/java/android/util/ArraySet.java +18 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.function.Consumer; import java.util.function.Predicate; /** Loading Loading @@ -747,6 +748,23 @@ public final class ArraySet<E> implements Collection<E>, Set<E> { return mSize; } /** * Performs the given action for all elements in the stored order. This implementation overrides * the default implementation to avoid using the {@link #iterator()}. * * @param action The action to be performed for each element */ @Override public void forEach(Consumer<? super E> action) { if (action == null) { throw new NullPointerException("action must not be null"); } for (int i = 0; i < mSize; ++i) { action.accept(valueAt(i)); } } @Override public Object[] toArray() { Object[] result = new Object[mSize]; Loading Loading
apct-tests/perftests/core/src/android/util/ArraySetPerfTest.java +33 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import java.util.function.Consumer; import java.util.function.Predicate; @RunWith(AndroidJUnit4.class) Loading @@ -38,6 +39,38 @@ public class ArraySetPerfTest { @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); @Test public void testForEach_Small() { BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); Consumer<Integer> consumer = (i) -> { }; while (state.keepRunning()) { for (int i = 0; i < NUM_ITERATIONS; ++i) { ArraySet<Integer> set = new ArraySet<>(); for (int j = 0; j < SET_SIZE_SMALL; j++) { set.add(j); } set.forEach(consumer); } } } @Test public void testForEach_Large() { BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); Consumer<Integer> consumer = (i) -> { }; while (state.keepRunning()) { for (int i = 0; i < NUM_ITERATIONS; ++i) { ArraySet<Integer> set = new ArraySet<>(); for (int j = 0; j < SET_SIZE_LARGE; j++) { set.add(j); } set.forEach(consumer); } } } @Test public void testValueAt_InBounds() { BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); Loading
core/api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -45993,6 +45993,7 @@ package android.util { method public boolean contains(Object); method public boolean containsAll(java.util.Collection<?>); method public void ensureCapacity(int); method public void forEach(java.util.function.Consumer<? super E>); method public int indexOf(Object); method public boolean isEmpty(); method public java.util.Iterator<E> iterator();
core/java/android/util/ArraySet.java +18 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.function.Consumer; import java.util.function.Predicate; /** Loading Loading @@ -747,6 +748,23 @@ public final class ArraySet<E> implements Collection<E>, Set<E> { return mSize; } /** * Performs the given action for all elements in the stored order. This implementation overrides * the default implementation to avoid using the {@link #iterator()}. * * @param action The action to be performed for each element */ @Override public void forEach(Consumer<? super E> action) { if (action == null) { throw new NullPointerException("action must not be null"); } for (int i = 0; i < mSize; ++i) { action.accept(valueAt(i)); } } @Override public Object[] toArray() { Object[] result = new Object[mSize]; Loading