mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-15 03:35:52 +00:00
Perf hack for Android: cache the result of Transaction.getValue(). This won't help once we split payments from transactions.
This commit is contained in:
parent
8c414fb172
commit
ece8d9a347
@ -376,11 +376,23 @@ public class Transaction extends ChildMessage implements Serializable {
|
||||
return v;
|
||||
}
|
||||
|
||||
@Nullable private Coin cachedValue;
|
||||
@Nullable private TransactionBag cachedForBag;
|
||||
|
||||
/**
|
||||
* Returns the difference of {@link Transaction#getValueSentToMe(TransactionBag)} and {@link Transaction#getValueSentFromMe(TransactionBag)}.
|
||||
*/
|
||||
public Coin getValue(TransactionBag wallet) throws ScriptException {
|
||||
return getValueSentToMe(wallet).subtract(getValueSentFromMe(wallet));
|
||||
// FIXME: TEMP PERF HACK FOR ANDROID - this crap can go away once we have a real payments API.
|
||||
boolean isAndroid = Utils.isAndroidRuntime();
|
||||
if (isAndroid && cachedValue != null && cachedForBag == wallet)
|
||||
return cachedValue;
|
||||
Coin result = getValueSentToMe(wallet).subtract(getValueSentFromMe(wallet));
|
||||
if (isAndroid) {
|
||||
cachedValue = result;
|
||||
cachedForBag = wallet;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -575,9 +575,13 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
private static int isAndroid = -1;
|
||||
public static boolean isAndroidRuntime() {
|
||||
final String runtime = System.getProperty("java.runtime.name");
|
||||
return runtime != null && runtime.equals("Android Runtime");
|
||||
if (isAndroid == -1) {
|
||||
final String runtime = System.getProperty("java.runtime.name");
|
||||
isAndroid = (runtime != null && runtime.equals("Android Runtime")) ? 1 : 0;
|
||||
}
|
||||
return isAndroid == 1;
|
||||
}
|
||||
|
||||
private static class Pair implements Comparable<Pair> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user