This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit 9dd85849635461835d629e3301b7808d4dfe35d6
Author: Gary Gregory <[email protected]>
AuthorDate: Sun Mar 20 14:27:10 2022 -0400

    Better concurrency with the Java 8 API ConcurrentMap#computeIfAbsent().
---
 .../java/org/apache/commons/lang3/time/FastDatePrinter.java | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java 
b/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java
index 697ad74..c836eda 100644
--- a/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java
+++ b/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java
@@ -1299,6 +1299,7 @@ public class FastDatePrinter implements DatePrinter, 
Serializable {
 
     private static final ConcurrentMap<TimeZoneDisplayKey, String> 
cTimeZoneDisplayCache =
         new ConcurrentHashMap<>(7);
+
     /**
      * <p>Gets the time zone display name, using a cache for performance.</p>
      *
@@ -1310,16 +1311,8 @@ public class FastDatePrinter implements DatePrinter, 
Serializable {
      */
     static String getTimeZoneDisplay(final TimeZone tz, final boolean 
daylight, final int style, final Locale locale) {
         final TimeZoneDisplayKey key = new TimeZoneDisplayKey(tz, daylight, 
style, locale);
-        String value = cTimeZoneDisplayCache.get(key);
-        if (value == null) {
-            // This is a very slow call, so cache the results.
-            value = tz.getDisplayName(daylight, style, locale);
-            final String prior = cTimeZoneDisplayCache.putIfAbsent(key, value);
-            if (prior != null) {
-                value= prior;
-            }
-        }
-        return value;
+        // This is a very slow call, so cache the results.
+        return cTimeZoneDisplayCache.computeIfAbsent(key, k -> 
tz.getDisplayName(daylight, style, locale));
     }
 
     /**

Reply via email to