Skip to content

Commit 96ab552

Browse files
committed
[nop] Update ThreadLocal consumers
1 parent 1a88936 commit 96ab552

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

src/taoensso/encore.cljc

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,45 +2718,48 @@
27182718

27192719
(comment (macroexpand '(msecs :weeks 3)))
27202720

2721-
#?(:clj
2722-
(defn- -simple-date-format
2723-
"Returns a SimpleDateFormat ThreadLocal proxy."
2724-
[pattern locale timezone]
2725-
(let [pattern
2726-
(case pattern
2727-
:iso8601 "yyyy-MM-dd'T'HH:mm:ss.SSSX"
2728-
:rss2 "EEE, dd MMM yyyy HH:mm:ss z"
2729-
pattern)
2730-
2731-
locale
2732-
(if (identical-kw? locale :jvm-default)
2733-
nil ; (Locale/getDefault)
2734-
locale)
2735-
2736-
timezone
2737-
(if (identical-kw? timezone :jvm-default)
2738-
nil ; (TimeZone/getDefault)
2739-
(if (identical-kw? timezone :utc)
2740-
(TimeZone/getTimeZone "UTC")
2741-
timezone))]
2742-
2743-
(threadlocal
2744-
(let [^SimpleDateFormat sdf
2745-
(if locale
2746-
(SimpleDateFormat. ^String pattern ^Locale locale)
2747-
(SimpleDateFormat. ^String pattern))]
2748-
(when timezone (.setTimeZone sdf ^TimeZone timezone))
2749-
sdf)))))
2750-
2751-
#?(:clj
2752-
(defn simple-date-format*
2753-
^java.text.SimpleDateFormat [pattern locale timezone]
2754-
(.get ^ThreadLocal (-simple-date-format pattern locale timezone))))
2721+
(declare fmemoize)
27552722

27562723
#?(:clj
2757-
(defn simple-date-format "Returns a thread-local `java.text.SimpleDateFormat`."
2758-
^java.text.SimpleDateFormat [pattern & [{:keys [locale timezone] :as opts}]]
2759-
(.get ^ThreadLocal (-simple-date-format pattern locale timezone))))
2724+
(let [get-threadlocal
2725+
(fmemoize
2726+
(fn [pattern locale timezone]
2727+
(threadlocal
2728+
(let [pattern
2729+
(case pattern
2730+
:iso8601 "yyyy-MM-dd'T'HH:mm:ss.SSSX"
2731+
:rss2 "EEE, dd MMM yyyy HH:mm:ss z"
2732+
pattern)
2733+
2734+
locale
2735+
(if (identical-kw? locale :jvm-default)
2736+
nil #_(Locale/getDefault)
2737+
locale)
2738+
2739+
timezone
2740+
(if (identical-kw? timezone :jvm-default)
2741+
nil #_(TimeZone/getDefault)
2742+
(if (identical-kw? timezone :utc)
2743+
(TimeZone/getTimeZone "UTC")
2744+
timezone))
2745+
2746+
^SimpleDateFormat sdf
2747+
(if locale
2748+
(SimpleDateFormat. ^String pattern ^Locale locale)
2749+
(SimpleDateFormat. ^String pattern))]
2750+
2751+
(when timezone (.setTimeZone sdf ^TimeZone timezone))
2752+
(do sdf)))))]
2753+
2754+
(defn simple-date-format*
2755+
"Returns a thread-local `java.text.SimpleDateFormat`."
2756+
^java.text.SimpleDateFormat [pattern locale timezone]
2757+
(.get ^ThreadLocal (get-threadlocal pattern locale timezone)))
2758+
2759+
(defn simple-date-format
2760+
"Returns a thread-local `java.text.SimpleDateFormat`."
2761+
^java.text.SimpleDateFormat [pattern & [{:keys [locale timezone] :as opts}]]
2762+
(.get ^ThreadLocal (get-threadlocal pattern locale timezone)))))
27602763

27612764
(comment (qb 1e5 (.format (simple-date-format "yyyy-MMM-dd") (Date.))))
27622765

@@ -3139,7 +3142,7 @@
31393142
"Private, don't use."
31403143
[n-min-fd n-max-fd]
31413144
#?(:clj
3142-
(let [nf-proxy
3145+
(let [tl:nf
31433146
(threadlocal
31443147
(let [nf (java.text.NumberFormat/getInstance java.util.Locale/US)]
31453148
(when (instance? java.text.DecimalFormat nf)
@@ -3152,7 +3155,7 @@
31523155
(.setDecimalSeparator \.)
31533156
(.setGroupingSeparator \,)))))))]
31543157

3155-
(fn [n] (.format ^java.text.NumberFormat (.get nf-proxy) n)))
3158+
(fn [n] (.format ^java.text.NumberFormat (.get tl:nf) n)))
31563159

31573160
:cljs
31583161
(let [nf
@@ -3222,8 +3225,6 @@
32223225

32233226
;;;; Name filter
32243227

3225-
(declare fmemoize)
3226-
32273228
(let [as-?qname as-?qname
32283229
always (fn always [_in] true)
32293230
never (fn never [_in] false)
@@ -3632,12 +3633,11 @@
36323633
(ReseedingSRNG. (java.security.SecureRandom/getInstanceStrong) 0)
36333634
(ReseedingSRNG. (java.security.SecureRandom/getInstance "SHA1SRNG") 0)))
36343635

3635-
(def ^:private rsrng* (threadlocal (reseeding-srng)))
3636-
3637-
(defn secure-rng
3638-
"Returns an auto-reseeding thread-local `java.security.SecureRandom`.
3639-
Favours security over performance. May block while waiting on entropy!"
3640-
^java.security.SecureRandom [] ((.get ^ThreadLocal rsrng*)))
3636+
(let [tl:rsrng (threadlocal (reseeding-srng))]
3637+
(defn secure-rng
3638+
"Returns an auto-reseeding thread-local `java.security.SecureRandom`.
3639+
Favours security over performance. May block while waiting on entropy!"
3640+
^java.security.SecureRandom [] ((.get tl:rsrng))))
36413641

36423642
(defn secure-rng-mock!!!
36433643
"Returns **INSECURE** `java.security.SecureRandom` mock instance backed by

0 commit comments

Comments
 (0)