Misc housekeeping
This commit is contained in:
parent
1df4847102
commit
e07ec91f41
1 changed files with 19 additions and 11 deletions
|
|
@ -710,8 +710,8 @@
|
||||||
|
|
||||||
;; Public `-freeze-with-meta!` with different arg order
|
;; Public `-freeze-with-meta!` with different arg order
|
||||||
(defn freeze-to-out!
|
(defn freeze-to-out!
|
||||||
"Serializes arg (any Clojure data type) to a DataOutput. Please note that
|
"Serializes arg (any Clojure data type) to a DataOutput.
|
||||||
this is a low-level util: in most cases you'll want `freeze` instead."
|
This is a low-level util: in most cases you'll want `freeze` instead."
|
||||||
[^DataOutput data-output x] (-freeze-with-meta! x data-output))
|
[^DataOutput data-output x] (-freeze-with-meta! x data-output))
|
||||||
|
|
||||||
(defmacro ^:private freezer [type & body]
|
(defmacro ^:private freezer [type & body]
|
||||||
|
|
@ -726,16 +726,22 @@
|
||||||
~@body)))
|
~@body)))
|
||||||
|
|
||||||
;;;; Caching ; Experimental
|
;;;; Caching ; Experimental
|
||||||
;; How much point is there in offering this feature if we already have LZ4?
|
|
||||||
|
|
||||||
;; Nb: don't use an auto initialValue; can cause thread-local state to
|
;; Nb: don't use an auto initialValue; can cause thread-local state to
|
||||||
;; accidentally hang around with the use of `freeze-to-out!`, etc.
|
;; accidentally hang around with the use of `freeze-to-out!`, etc.
|
||||||
;; Safer to require explicit activation through `with-cache`.
|
;; Safer to require explicit activation through `with-cache`.
|
||||||
(def ^ThreadLocal -cache-proxy (proxy [ThreadLocal] []))
|
(def ^ThreadLocal -cache-proxy
|
||||||
|
"{[<x> <meta>] <idx>} for freezing, {<idx> <x-with-meta>} for thawing."
|
||||||
|
(proxy [ThreadLocal] []))
|
||||||
|
|
||||||
(defmacro ^:private with-cache
|
(defmacro ^:private with-cache
|
||||||
"Experimental! Executes body with support for freezing and thawing
|
"Experimental, subject to change.
|
||||||
cached values. See also `cache`."
|
Executes body with support for freezing/thawing cached values.
|
||||||
|
|
||||||
|
This is a low-level util: you won't need to use this yourself unless
|
||||||
|
you're using `freeze-to-out!` or `thaw-from-in!` (also low-level utils).
|
||||||
|
|
||||||
|
See also `cache`."
|
||||||
[& body]
|
[& body]
|
||||||
`(try
|
`(try
|
||||||
(.set -cache-proxy (enc/-vol! nil))
|
(.set -cache-proxy (enc/-vol! nil))
|
||||||
|
|
@ -744,9 +750,10 @@
|
||||||
|
|
||||||
(deftype CacheWrapped [val])
|
(deftype CacheWrapped [val])
|
||||||
(defn cache
|
(defn cache
|
||||||
"Experimental! Wraps value so that future writes of the same wrapped
|
"Experimental, subject to change.
|
||||||
value with same metadata will be efficiently encoded as references to
|
|
||||||
this one.
|
Wraps value so that future writes of the same wrapped value with same
|
||||||
|
metadata will be efficiently encoded as references to this one.
|
||||||
|
|
||||||
(freeze [(cache \"foo\") (cache \"foo\") (cache \"foo\")])
|
(freeze [(cache \"foo\") (cache \"foo\") (cache \"foo\")])
|
||||||
will incl. a single \"foo\", plus 2x single-byte references to \"foo\"."
|
will incl. a single \"foo\", plus 2x single-byte references to \"foo\"."
|
||||||
|
|
@ -1085,8 +1092,9 @@
|
||||||
|
|
||||||
(defn thaw-from-in!
|
(defn thaw-from-in!
|
||||||
"Deserializes a frozen object from given DataInput to its original Clojure
|
"Deserializes a frozen object from given DataInput to its original Clojure
|
||||||
data type. Please note that this is a low-level util: in most cases you'll
|
data type.
|
||||||
want `thaw` instead."
|
|
||||||
|
This is a low-level util: in most cases you'll want `thaw` instead."
|
||||||
[^DataInput data-input]
|
[^DataInput data-input]
|
||||||
(let [in data-input
|
(let [in data-input
|
||||||
type-id (.readByte in)]
|
type-id (.readByte in)]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue