Cache currencyCode

Extract variable

getCurrencyCode get called very often (Comparatos) so we cache result.
This commit is contained in:
chimp1984 2020-12-15 00:59:05 -05:00
parent 02d163f5dc
commit 9fc4f61bf6
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3

View File

@ -109,6 +109,10 @@ public class Offer implements NetworkPayload, PersistablePayload {
@Setter @Setter
transient private PriceFeedService priceFeedService; transient private PriceFeedService priceFeedService;
// Used only as cache
@Nullable
transient private String currencyCode;
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Constructor // Constructor
@ -346,8 +350,9 @@ public class Offer implements NetworkPayload, PersistablePayload {
public Optional<String> getAccountAgeWitnessHashAsHex() { public Optional<String> getAccountAgeWitnessHashAsHex() {
if (getExtraDataMap() != null && getExtraDataMap().containsKey(OfferPayload.ACCOUNT_AGE_WITNESS_HASH)) Map<String, String> extraDataMap = getExtraDataMap();
return Optional.of(getExtraDataMap().get(OfferPayload.ACCOUNT_AGE_WITNESS_HASH)); if (extraDataMap != null && extraDataMap.containsKey(OfferPayload.ACCOUNT_AGE_WITNESS_HASH))
return Optional.of(extraDataMap.get(OfferPayload.ACCOUNT_AGE_WITNESS_HASH));
else else
return Optional.empty(); return Optional.empty();
} }
@ -421,9 +426,14 @@ public class Offer implements NetworkPayload, PersistablePayload {
} }
public String getCurrencyCode() { public String getCurrencyCode() {
return offerPayload.getBaseCurrencyCode().equals("BTC") ? if (currencyCode != null) {
return currencyCode;
}
currencyCode = offerPayload.getBaseCurrencyCode().equals("BTC") ?
offerPayload.getCounterCurrencyCode() : offerPayload.getCounterCurrencyCode() :
offerPayload.getBaseCurrencyCode(); offerPayload.getBaseCurrencyCode();
return currencyCode;
} }
public long getProtocolVersion() { public long getProtocolVersion() {