Use PooledLambda.obtainMessage() when possible

As its JavaDoc says, in most of cases PooledLambda.obtainMessage() is
a better choice than PooledLambda.obtainRunnable().

If PooledLambda.obtainRunnable() is really necessary, let's make sure
to call recycleOnUse() whenever possible.

Test: presubmit
Change-Id: I3dbe500f49c0df187f2ffefd11c71836696dfd4e
This commit is contained in:
Yohei Yukawa
2018-09-22 13:13:10 -07:00
parent 21ba5d4f3f
commit e2fa39ec3d
5 changed files with 20 additions and 18 deletions

View File

@@ -1541,7 +1541,7 @@ public final class ActivityThread extends ClientTransactionHandler {
public void scheduleTrimMemory(int level) {
final Runnable r = PooledLambda.obtainRunnable(ActivityThread::handleTrimMemory,
ActivityThread.this, level);
ActivityThread.this, level).recycleOnUse();
// Schedule trimming memory after drawing the frame to minimize jank-risk.
Choreographer choreographer = Choreographer.getMainThreadInstance();
if (choreographer != null) {

View File

@@ -1197,10 +1197,9 @@ public final class UiAutomation {
}
if (listener != null) {
// Calling out only without a lock held.
mLocalCallbackHandler.post(PooledLambda.obtainRunnable(
mLocalCallbackHandler.sendMessage(PooledLambda.obtainMessage(
OnAccessibilityEventListener::onAccessibilityEvent,
listener, AccessibilityEvent.obtain(event))
.recycleOnUse());
listener, AccessibilityEvent.obtain(event)));
}
}