Simplification

This commit is contained in:
M66B 2019-08-16 09:58:12 +02:00
parent 60ed5fb503
commit d36bb086b2
2 changed files with 9 additions and 18 deletions

View File

@ -89,17 +89,15 @@ public abstract class ComputableLiveData<T> {
@Override @Override
public void run() { public void run() {
boolean computed; boolean computed;
boolean once;
long last;
do { do {
computed = false; computed = false;
// compute can happen only in 1 thread but no reason to lock others. // compute can happen only in 1 thread but no reason to lock others.
if (mComputing.compareAndSet(false, true)) { if (mComputing.compareAndSet(false, true)) {
// as long as it is invalid, keep computing. // as long as it is invalid, keep computing.
try { try {
once = true;
last = android.os.SystemClock.elapsedRealtime();
T value = null; T value = null;
boolean once = true;
long last = android.os.SystemClock.elapsedRealtime();
while (mInvalid.compareAndSet(true, false)) { while (mInvalid.compareAndSet(true, false)) {
long now = android.os.SystemClock.elapsedRealtime(); long now = android.os.SystemClock.elapsedRealtime();
if (value != null && (once || last + 2500 < now)) { if (value != null && (once || last + 2500 < now)) {

View File

@ -1,20 +1,13 @@
--- /home/marcel/support/lifecycle/lifecycle-livedata/src/main/java/androidx/lifecycle/ComputableLiveData.java 2019-07-27 12:47:44.348985792 +0200 diff --git a/home/marcel/support/lifecycle/lifecycle-livedata/src/main/java/androidx/lifecycle/ComputableLiveData.java b/app/src/main/java/androidx/lifecycle/ComputableLiveData.java
+++ app/src/main/java/androidx/lifecycle/ComputableLiveData.java 2019-08-14 10:25:21.881453609 +0200 index 837a35dbf..cc375b15b 100644
@@ -89,14 +89,25 @@ public abstract class ComputableLiveData --- a/home/marcel/support/lifecycle/lifecycle-livedata/src/main/java/androidx/lifecycle/ComputableLiveData.java
@Override +++ b/app/src/main/java/androidx/lifecycle/ComputableLiveData.java
public void run() { @@ -96,7 +96,16 @@ public abstract class ComputableLiveData<T> {
boolean computed;
+ boolean once;
+ long last;
do {
computed = false;
// compute can happen only in 1 thread but no reason to lock others.
if (mComputing.compareAndSet(false, true)) {
// as long as it is invalid, keep computing. // as long as it is invalid, keep computing.
try { try {
+ once = true;
+ last = android.os.SystemClock.elapsedRealtime();
T value = null; T value = null;
+ boolean once = true;
+ long last = android.os.SystemClock.elapsedRealtime();
while (mInvalid.compareAndSet(true, false)) { while (mInvalid.compareAndSet(true, false)) {
+ long now = android.os.SystemClock.elapsedRealtime(); + long now = android.os.SystemClock.elapsedRealtime();
+ if (value != null && (once || last + 2500 < now)) { + if (value != null && (once || last + 2500 < now)) {