Skip to content

Commit

Permalink
Add null checks, improve comment
Browse files Browse the repository at this point in the history
  • Loading branch information
chimp1984 committed Dec 16, 2020
1 parent 0f084d3 commit ecad724
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions core/src/main/java/bisq/core/locale/CurrencyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public static void setup() {

// Calls to isFiatCurrency and isCryptoCurrency are very frequent so we use a cache of the results.
// The main improvement was already achieved with using memoize for the source maps, but
// the caching still improves performance by about 20% for isCryptoCurrency and about 100%
// for isFiatCurrency calls.
// the caching still reduces performance costs by about 20% for isCryptoCurrency (1752 ms vs 2121 ms) and about 50%
// for isFiatCurrency calls (1777 ms vs 3467 ms).
// See: https://github.com/bisq-network/bisq/pull/4955#issuecomment-745302802
private static final Map<String, Boolean> isFiatCurrencyMap = new ConcurrentHashMap<>();
private static final Map<String, Boolean> isCryptoCurrencyMap = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -399,7 +399,7 @@ public static List<TradeCurrency> getMatureMarketCurrencies() {
}

public static boolean isFiatCurrency(String currencyCode) {
if (isFiatCurrencyMap.containsKey(currencyCode)) {
if (currencyCode != null && isFiatCurrencyMap.containsKey(currencyCode)) {
return isFiatCurrencyMap.get(currencyCode);
}

Expand Down Expand Up @@ -438,7 +438,7 @@ public static Optional<FiatCurrency> getFiatCurrency(String currencyCode) {
* contains 3 entries (CryptoCurrency, Fiat, Undefined).
*/
public static boolean isCryptoCurrency(String currencyCode) {
if (isCryptoCurrencyMap.containsKey(currencyCode)) {
if (currencyCode != null && isCryptoCurrencyMap.containsKey(currencyCode)) {
return isCryptoCurrencyMap.get(currencyCode);
}

Expand Down

0 comments on commit ecad724

Please sign in to comment.