|
2718 | 2718 |
|
2719 | 2719 | (comment (macroexpand '(msecs :weeks 3))) |
2720 | 2720 |
|
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) |
2755 | 2722 |
|
2756 | 2723 | #?(: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))))) |
2760 | 2763 |
|
2761 | 2764 | (comment (qb 1e5 (.format (simple-date-format "yyyy-MMM-dd") (Date.)))) |
2762 | 2765 |
|
|
3139 | 3142 | "Private, don't use." |
3140 | 3143 | [n-min-fd n-max-fd] |
3141 | 3144 | #?(:clj |
3142 | | - (let [nf-proxy |
| 3145 | + (let [tl:nf |
3143 | 3146 | (threadlocal |
3144 | 3147 | (let [nf (java.text.NumberFormat/getInstance java.util.Locale/US)] |
3145 | 3148 | (when (instance? java.text.DecimalFormat nf) |
|
3152 | 3155 | (.setDecimalSeparator \.) |
3153 | 3156 | (.setGroupingSeparator \,)))))))] |
3154 | 3157 |
|
3155 | | - (fn [n] (.format ^java.text.NumberFormat (.get nf-proxy) n))) |
| 3158 | + (fn [n] (.format ^java.text.NumberFormat (.get tl:nf) n))) |
3156 | 3159 |
|
3157 | 3160 | :cljs |
3158 | 3161 | (let [nf |
|
3222 | 3225 |
|
3223 | 3226 | ;;;; Name filter |
3224 | 3227 |
|
3225 | | -(declare fmemoize) |
3226 | | - |
3227 | 3228 | (let [as-?qname as-?qname |
3228 | 3229 | always (fn always [_in] true) |
3229 | 3230 | never (fn never [_in] false) |
|
3632 | 3633 | (ReseedingSRNG. (java.security.SecureRandom/getInstanceStrong) 0) |
3633 | 3634 | (ReseedingSRNG. (java.security.SecureRandom/getInstance "SHA1SRNG") 0))) |
3634 | 3635 |
|
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)))) |
3641 | 3641 |
|
3642 | 3642 | (defn secure-rng-mock!!! |
3643 | 3643 | "Returns **INSECURE** `java.security.SecureRandom` mock instance backed by |
|
0 commit comments