summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Riddle Hsu <riddlehsu@google.com> 2022-10-18 17:37:48 +0800
committer Riddle Hsu <riddlehsu@google.com> 2022-10-18 12:30:20 +0000
commit4c4a9a77c50db132a6f7f42789f4f8d4b55d2207 (patch)
tree4cc4d7d9f64bfdc2fac71c743b3dbd5b109c6bff
parent8f0e43537bca8be5ec58607e5c5ac8f9836f2edd (diff)
Remove PooledConsumer
Those methods are not used anymore. And the regular lambda is already good in performance. Bug: 120160274 Test: atest LambdaPerfTest Change-Id: Id3d736da726d003ce9b57ff72193d33e244b6b30
-rwxr-xr-xcore/java/com/android/internal/util/function/pooled/OmniFunction.java19
-rw-r--r--core/java/com/android/internal/util/function/pooled/PooledConsumer.java31
-rw-r--r--core/java/com/android/internal/util/function/pooled/PooledFunction.java36
-rwxr-xr-xcore/java/com/android/internal/util/function/pooled/PooledLambda.java173
-rw-r--r--core/java/com/android/internal/util/function/pooled/PooledPredicate.java5
-rw-r--r--tests/benchmarks/internal/src/com/android/internal/LambdaPerfTest.java40
6 files changed, 17 insertions, 287 deletions
diff --git a/core/java/com/android/internal/util/function/pooled/OmniFunction.java b/core/java/com/android/internal/util/function/pooled/OmniFunction.java
index b6d2dedc1bfd..931477f0b332 100755
--- a/core/java/com/android/internal/util/function/pooled/OmniFunction.java
+++ b/core/java/com/android/internal/util/function/pooled/OmniFunction.java
@@ -51,13 +51,13 @@ import java.util.function.Function;
* @hide
*/
abstract class OmniFunction<A, B, C, D, E, F, G, H, I, J, K, R> implements
- PooledFunction<A, R>, BiFunction<A, B, R>, TriFunction<A, B, C, R>,
+ BiFunction<A, B, R>, TriFunction<A, B, C, R>,
QuadFunction<A, B, C, D, R>, QuintFunction<A, B, C, D, E, R>,
HexFunction<A, B, C, D, E, F, R>, HeptFunction<A, B, C, D, E, F, G, R>,
OctFunction<A, B, C, D, E, F, G, H, R>, NonaFunction<A, B, C, D, E, F, G, H, I, R>,
DecFunction<A, B, C, D, E, F, G, H, I, J, R>,
UndecFunction<A, B, C, D, E, F, G, H, I, J, K, R>,
- PooledConsumer<A>, BiConsumer<A, B>, TriConsumer<A, B, C>, QuadConsumer<A, B, C, D>,
+ BiConsumer<A, B>, TriConsumer<A, B, C>, QuadConsumer<A, B, C, D>,
QuintConsumer<A, B, C, D, E>, HexConsumer<A, B, C, D, E, F>,
HeptConsumer<A, B, C, D, E, F, G>, OctConsumer<A, B, C, D, E, F, G, H>,
NonaConsumer<A, B, C, D, E, F, G, H, I>, DecConsumer<A, B, C, D, E, F, G, H, I, J>,
@@ -73,11 +73,6 @@ abstract class OmniFunction<A, B, C, D, E, F, G, H, I, J, K, R> implements
return invoke(o, o2, null, null, null, null, null, null, null, null, null);
}
- @Override
- public R apply(A o) {
- return invoke(o, null, null, null, null, null, null, null, null, null, null);
- }
-
public abstract <V> OmniFunction<A, B, C, D, E, F, G, H, I, J, K, V> andThen(
Function<? super R, ? extends V> after);
public abstract OmniFunction<A, B, C, D, E, F, G, H, I, J, K, R> negate();
@@ -88,11 +83,6 @@ abstract class OmniFunction<A, B, C, D, E, F, G, H, I, J, K, R> implements
}
@Override
- public void accept(A o) {
- invoke(o, null, null, null, null, null, null, null, null, null, null);
- }
-
- @Override
public void run() {
invoke(null, null, null, null, null, null, null, null, null, null, null);
}
@@ -133,11 +123,6 @@ abstract class OmniFunction<A, B, C, D, E, F, G, H, I, J, K, R> implements
}
@Override
- public PooledConsumer<A> asConsumer() {
- return this;
- }
-
- @Override
public R apply(A a, B b, C c) {
return invoke(a, b, c, null, null, null, null, null, null, null, null);
}
diff --git a/core/java/com/android/internal/util/function/pooled/PooledConsumer.java b/core/java/com/android/internal/util/function/pooled/PooledConsumer.java
deleted file mode 100644
index f66586ee6791..000000000000
--- a/core/java/com/android/internal/util/function/pooled/PooledConsumer.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.internal.util.function.pooled;
-
-import java.util.function.Consumer;
-
-/**
- * {@link Consumer} + {@link PooledLambda}
- *
- * @see PooledLambda
- * @hide
- */
-public interface PooledConsumer<T> extends PooledLambda, Consumer<T> {
-
- /** @inheritDoc */
- PooledConsumer<T> recycleOnUse();
-}
diff --git a/core/java/com/android/internal/util/function/pooled/PooledFunction.java b/core/java/com/android/internal/util/function/pooled/PooledFunction.java
deleted file mode 100644
index 1f166fafc7e6..000000000000
--- a/core/java/com/android/internal/util/function/pooled/PooledFunction.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.internal.util.function.pooled;
-
-import java.util.function.Function;
-
-/**
- * {@link Function} + {@link PooledLambda}
- *
- * @see PooledLambda
- * @hide
- */
-public interface PooledFunction<A, R> extends PooledLambda, Function<A, R> {
-
- /**
- * Ignores the result
- */
- PooledConsumer<A> asConsumer();
-
- /** @inheritDoc */
- PooledFunction<A, R> recycleOnUse();
-}
diff --git a/core/java/com/android/internal/util/function/pooled/PooledLambda.java b/core/java/com/android/internal/util/function/pooled/PooledLambda.java
index 2bfde242a987..bdc8a668a7f7 100755
--- a/core/java/com/android/internal/util/function/pooled/PooledLambda.java
+++ b/core/java/com/android/internal/util/function/pooled/PooledLambda.java
@@ -233,24 +233,6 @@ public interface PooledLambda {
}
/**
- * {@link PooledConsumer} factory
- *
- * @param function non-capturing lambda(typically an unbounded method reference)
- * to be invoked on call
- * @param arg1 placeholder for a missing argument. Use {@link #__} to get one
- * @param arg2 parameter supplied to {@code function} on call
- * @return a {@link PooledConsumer}, equivalent to lambda:
- * {@code (arg1) -> function(arg1, arg2) }
- */
- static <A, B> PooledConsumer<A> obtainConsumer(
- BiConsumer<? super A, ? super B> function,
- ArgumentPlaceholder<A> arg1, B arg2) {
- return acquire(PooledLambdaImpl.sPool,
- function, 2, 1, ReturnType.VOID, arg1, arg2, null, null, null, null, null, null,
- null, null, null, null);
- }
-
- /**
* {@link PooledPredicate} factory
*
* @param function non-capturing lambda(typically an unbounded method reference)
@@ -329,24 +311,6 @@ public interface PooledLambda {
}
/**
- * {@link PooledConsumer} factory
- *
- * @param function non-capturing lambda(typically an unbounded method reference)
- * to be invoked on call
- * @param arg1 parameter supplied to {@code function} on call
- * @param arg2 placeholder for a missing argument. Use {@link #__} to get one
- * @return a {@link PooledConsumer}, equivalent to lambda:
- * {@code (arg2) -> function(arg1, arg2) }
- */
- static <A, B> PooledConsumer<B> obtainConsumer(
- BiConsumer<? super A, ? super B> function,
- A arg1, ArgumentPlaceholder<B> arg2) {
- return acquire(PooledLambdaImpl.sPool,
- function, 2, 1, ReturnType.VOID, arg1, arg2, null, null, null, null, null, null,
- null, null, null, null);
- }
-
- /**
* {@link PooledPredicate} factory
*
* @param function non-capturing lambda(typically an unbounded method reference)
@@ -418,63 +382,6 @@ public interface PooledLambda {
}
/**
- * {@link PooledConsumer} factory
- *
- * @param function non-capturing lambda(typically an unbounded method reference)
- * to be invoked on call
- * @param arg1 placeholder for a missing argument. Use {@link #__} to get one
- * @param arg2 parameter supplied to {@code function} on call
- * @param arg3 parameter supplied to {@code function} on call
- * @return a {@link PooledConsumer}, equivalent to lambda:
- * {@code (arg1) -> function(arg1, arg2, arg3) }
- */
- static <A, B, C> PooledConsumer<A> obtainConsumer(
- TriConsumer<? super A, ? super B, ? super C> function,
- ArgumentPlaceholder<A> arg1, B arg2, C arg3) {
- return acquire(PooledLambdaImpl.sPool,
- function, 3, 1, ReturnType.VOID, arg1, arg2, arg3, null, null, null, null, null,
- null, null, null, null);
- }
-
- /**
- * {@link PooledConsumer} factory
- *
- * @param function non-capturing lambda(typically an unbounded method reference)
- * to be invoked on call
- * @param arg1 parameter supplied to {@code function} on call
- * @param arg2 placeholder for a missing argument. Use {@link #__} to get one
- * @param arg3 parameter supplied to {@code function} on call
- * @return a {@link PooledConsumer}, equivalent to lambda:
- * {@code (arg2) -> function(arg1, arg2, arg3) }
- */
- static <A, B, C> PooledConsumer<B> obtainConsumer(
- TriConsumer<? super A, ? super B, ? super C> function,
- A arg1, ArgumentPlaceholder<B> arg2, C arg3) {
- return acquire(PooledLambdaImpl.sPool,
- function, 3, 1, ReturnType.VOID, arg1, arg2, arg3, null, null, null, null, null,
- null, null, null, null);
- }
-
- /**
- * {@link PooledConsumer} factory
- *
- * @param function non-capturing lambda(typically an unbounded method reference)
- * to be invoked on call
- * @param arg1 parameter supplied to {@code function} on call
- * @param arg2 parameter supplied to {@code function} on call
- * @param arg3 placeholder for a missing argument. Use {@link #__} to get one
- * @return a {@link PooledConsumer}, equivalent to lambda:
- * {@code (arg3) -> function(arg1, arg2, arg3) }
- */
- static <A, B, C> PooledConsumer<C> obtainConsumer(
- TriConsumer<? super A, ? super B, ? super C> function,
- A arg1, B arg2, ArgumentPlaceholder<C> arg3) {
- return acquire(PooledLambdaImpl.sPool,
- function, 3, 1, ReturnType.VOID, arg1, arg2, arg3, null, null, null, null, null,
- null, null, null, null);
- }
-
- /**
* Factory of {@link Message}s that contain an
* ({@link PooledLambda#recycleOnUse auto-recycling}) {@link PooledRunnable} as its
* {@link Message#getCallback internal callback}.
@@ -530,86 +437,6 @@ public interface PooledLambda {
}
/**
- * {@link PooledConsumer} factory
- *
- * @param function non-capturing lambda(typically an unbounded method reference)
- * to be invoked on call
- * @param arg1 placeholder for a missing argument. Use {@link #__} to get one
- * @param arg2 parameter supplied to {@code function} on call
- * @param arg3 parameter supplied to {@code function} on call
- * @param arg4 parameter supplied to {@code function} on call
- * @return a {@link PooledConsumer}, equivalent to lambda:
- * {@code (arg1) -> function(arg1, arg2, arg3, arg4) }
- */
- static <A, B, C, D> PooledConsumer<A> obtainConsumer(
- QuadConsumer<? super A, ? super B, ? super C, ? super D> function,
- ArgumentPlaceholder<A> arg1, B arg2, C arg3, D arg4) {
- return acquire(PooledLambdaImpl.sPool,
- function, 4, 1, ReturnType.VOID, arg1, arg2, arg3, arg4, null, null, null, null,
- null, null, null, null);
- }
-
- /**
- * {@link PooledConsumer} factory
- *
- * @param function non-capturing lambda(typically an unbounded method reference)
- * to be invoked on call
- * @param arg1 parameter supplied to {@code function} on call
- * @param arg2 placeholder for a missing argument. Use {@link #__} to get one
- * @param arg3 parameter supplied to {@code function} on call
- * @param arg4 parameter supplied to {@code function} on call
- * @return a {@link PooledConsumer}, equivalent to lambda:
- * {@code (arg2) -> function(arg1, arg2, arg3, arg4) }
- */
- static <A, B, C, D> PooledConsumer<B> obtainConsumer(
- QuadConsumer<? super A, ? super B, ? super C, ? super D> function,
- A arg1, ArgumentPlaceholder<B> arg2, C arg3, D arg4) {
- return acquire(PooledLambdaImpl.sPool,
- function, 4, 1, ReturnType.VOID, arg1, arg2, arg3, arg4, null, null, null, null,
- null, null, null, null);
- }
-
- /**
- * {@link PooledConsumer} factory
- *
- * @param function non-capturing lambda(typically an unbounded method reference)
- * to be invoked on call
- * @param arg1 parameter supplied to {@code function} on call
- * @param arg2 parameter supplied to {@code function} on call
- * @param arg3 placeholder for a missing argument. Use {@link #__} to get one
- * @param arg4 parameter supplied to {@code function} on call
- * @return a {@link PooledConsumer}, equivalent to lambda:
- * {@code (arg3) -> function(arg1, arg2, arg3, arg4) }
- */
- static <A, B, C, D> PooledConsumer<C> obtainConsumer(
- QuadConsumer<? super A, ? super B, ? super C, ? super D> function,
- A arg1, B arg2, ArgumentPlaceholder<C> arg3, D arg4) {
- return acquire(PooledLambdaImpl.sPool,
- function, 4, 1, ReturnType.VOID, arg1, arg2, arg3, arg4, null, null, null, null,
- null, null, null, null);
- }
-
- /**
- * {@link PooledConsumer} factory
- *
- * @param function non-capturing lambda(typically an unbounded method reference)
- * to be invoked on call
- * @param arg1 parameter supplied to {@code function} on call
- * @param arg2 parameter supplied to {@code function} on call
- * @param arg3 parameter supplied to {@code function} on call
- * @param arg4 placeholder for a missing argument. Use {@link #__} to get one
- * @return a {@link PooledConsumer}, equivalent to lambda:
- * {@code (arg4) -> function(arg1, arg2, arg3, arg4) }
- */
- static <A, B, C, D> PooledConsumer<D> obtainConsumer(
- QuadConsumer<? super A, ? super B, ? super C, ? super D> function,
- A arg1, B arg2, C arg3, ArgumentPlaceholder<D> arg4) {
- return acquire(PooledLambdaImpl.sPool,
- function, 4, 1, ReturnType.VOID, arg1, arg2, arg3, arg4, null, null, null, null,
- null, null, null, null);
- }
-
- /**
* Factory of {@link Message}s that contain an
* ({@link PooledLambda#recycleOnUse auto-recycling}) {@link PooledRunnable} as its
* {@link Message#getCallback internal callback}.
diff --git a/core/java/com/android/internal/util/function/pooled/PooledPredicate.java b/core/java/com/android/internal/util/function/pooled/PooledPredicate.java
index 9b14366452e5..91a8607677a5 100644
--- a/core/java/com/android/internal/util/function/pooled/PooledPredicate.java
+++ b/core/java/com/android/internal/util/function/pooled/PooledPredicate.java
@@ -26,11 +26,6 @@ import java.util.function.Predicate;
*/
public interface PooledPredicate<T> extends PooledLambda, Predicate<T> {
- /**
- * Ignores the result
- */
- PooledConsumer<T> asConsumer();
-
/** @inheritDoc */
PooledPredicate<T> recycleOnUse();
}
diff --git a/tests/benchmarks/internal/src/com/android/internal/LambdaPerfTest.java b/tests/benchmarks/internal/src/com/android/internal/LambdaPerfTest.java
index 2001c04bd645..0a03e8d6534a 100644
--- a/tests/benchmarks/internal/src/com/android/internal/LambdaPerfTest.java
+++ b/tests/benchmarks/internal/src/com/android/internal/LambdaPerfTest.java
@@ -29,7 +29,6 @@ import android.util.Log;
import androidx.test.filters.LargeTest;
-import com.android.internal.util.function.pooled.PooledConsumer;
import com.android.internal.util.function.pooled.PooledLambda;
import com.android.internal.util.function.pooled.PooledPredicate;
@@ -46,7 +45,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CountDownLatch;
-import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -94,27 +92,27 @@ public class LambdaPerfTest {
};
@Test
- public void test1ParamConsumer() {
- evaluate(LAMBDA_FORM_REGULAR, () -> forAllTask(t -> t.doSomething(mTask)));
+ public void test1ParamPredicate() {
+ evaluate(LAMBDA_FORM_REGULAR, () -> handleTask(t -> t.doSomething(mTaskId, mTime)));
evaluate(LAMBDA_FORM_POOLED, () -> {
- final PooledConsumer c = PooledLambda.obtainConsumer(Task::doSomething,
- PooledLambda.__(Task.class), mTask);
- forAllTask(c);
+ final PooledPredicate c = PooledLambda.obtainPredicate(Task::doSomething,
+ PooledLambda.__(Task.class), mTaskId, mTime);
+ handleTask(c);
c.recycle();
});
}
@Test
- public void test2PrimitiveParamsConsumer() {
+ public void test2PrimitiveParamsPredicate() {
// Not in Integer#IntegerCache (-128~127) for autoboxing, that may create new object.
mTaskId = 12345;
mTime = 54321;
- evaluate(LAMBDA_FORM_REGULAR, () -> forAllTask(t -> t.doSomething(mTaskId, mTime)));
+ evaluate(LAMBDA_FORM_REGULAR, () -> handleTask(t -> t.doSomething(mTaskId, mTime)));
evaluate(LAMBDA_FORM_POOLED, () -> {
- final PooledConsumer c = PooledLambda.obtainConsumer(Task::doSomething,
+ final PooledPredicate c = PooledLambda.obtainPredicate(Task::doSomething,
PooledLambda.__(Task.class), mTaskId, mTime);
- forAllTask(c);
+ handleTask(c);
c.recycle();
});
}
@@ -164,15 +162,15 @@ public class LambdaPerfTest {
public void testMultiThread() {
final int numThread = 3;
- final Runnable regularAction = () -> forAllTask(t -> t.doSomething(mTask));
+ final Runnable regularAction = () -> handleTask(t -> t.doSomething(mTaskId, mTime));
final Runnable[] regularActions = new Runnable[numThread];
Arrays.fill(regularActions, regularAction);
evaluateMultiThread(LAMBDA_FORM_REGULAR, regularActions);
final Runnable pooledAction = () -> {
- final PooledConsumer c = PooledLambda.obtainConsumer(Task::doSomething,
- PooledLambda.__(Task.class), mTask);
- forAllTask(c);
+ final PooledPredicate c = PooledLambda.obtainPredicate(Task::doSomething,
+ PooledLambda.__(Task.class), mTaskId, mTime);
+ handleTask(c);
c.recycle();
};
final Runnable[] pooledActions = new Runnable[numThread];
@@ -180,12 +178,6 @@ public class LambdaPerfTest {
evaluateMultiThread(LAMBDA_FORM_POOLED, pooledActions);
}
- private void forAllTask(Consumer<Task> callback) {
- for (int i = mTasks.size() - 1; i >= 0; i--) {
- callback.accept(mTasks.get(i));
- }
- }
-
private void handleTask(Predicate<Task> callback) {
for (int i = mTasks.size() - 1; i >= 0; i--) {
final Task task = mTasks.get(i);
@@ -318,10 +310,8 @@ public class LambdaPerfTest {
void doSomething() {
}
- void doSomething(Task t) {
- }
-
- void doSomething(int taskId, long time) {
+ boolean doSomething(int taskId, long time) {
+ return false;
}
boolean doSomething(Rect bounds, boolean top, int taskId) {