From f5b5e6ff550cf94c5b56fc33dd4bd65422afa26c Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Mon, 8 Oct 2018 15:03:30 +0700 Subject: [PATCH] PyUtil: use computeIfAbsent (in particular to avoid `optional is compared with null` --- python/src/com/jetbrains/python/psi/PyUtil.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/python/src/com/jetbrains/python/psi/PyUtil.java b/python/src/com/jetbrains/python/psi/PyUtil.java index bca2b6a394c2..023386f81f56 100644 --- a/python/src/com/jetbrains/python/psi/PyUtil.java +++ b/python/src/com/jetbrains/python/psi/PyUtil.java @@ -814,11 +814,7 @@ public class PyUtil { // Don't use ConcurrentHashMap#computeIfAbsent(), it blocks if the function tries to update the cache recursively for the same key // during computation. We can accept here that some values will be computed several times due to non-atomic updates. final Optional

wrappedParam = Optional.ofNullable(param); - Optional value = cache.get(wrappedParam); - if (value == null) { - value = Optional.ofNullable(f.fun(param)); - cache.put(wrappedParam, value); - } + Optional value = cache.computeIfAbsent(wrappedParam, k -> Optional.ofNullable(f.fun(param))); return value.orElse(null); }