Remove :print-dup? option (no longer useful since switch to edn/read-string)

This commit is contained in:
Peter Taoussanis 2013-08-07 17:52:00 +07:00
parent efa56eca73
commit d3120f0246
2 changed files with 9 additions and 16 deletions

View file

@ -33,7 +33,7 @@
(def ^:const id-bytes (int 2)) (def ^:const id-bytes (int 2))
(def ^:const id-nil (int 3)) (def ^:const id-nil (int 3))
(def ^:const id-boolean (int 4)) (def ^:const id-boolean (int 4))
(def ^:const id-reader (int 5)) ; Fallback: *print-dup* pr-str output (def ^:const id-reader (int 5)) ; Fallback: pr-str output
(def ^:const id-char (int 10)) (def ^:const id-char (int 10))
;; 11 ;; 11
@ -98,12 +98,8 @@
(defn freeze-to-stream! (defn freeze-to-stream!
"Low-level API. Serializes arg (any Clojure data type) to a DataOutputStream." "Low-level API. Serializes arg (any Clojure data type) to a DataOutputStream."
[^DataOutputStream data-output-stream x & [{:keys [print-dup?] [^DataOutputStream data-output-stream x & _]
:or {print-dup? true}}]] (freeze-to-stream data-output-stream x))
(if (identical? *print-dup* print-dup?)
(freeze-to-stream data-output-stream x)
(binding [*print-dup* print-dup?] ; Expensive
(freeze-to-stream data-output-stream x))))
(defmacro ^:private freezer (defmacro ^:private freezer
"Helper to extend Freezable protocol." "Helper to extend Freezable protocol."
@ -196,14 +192,13 @@
"Serializes arg (any Clojure data type) to a byte array. Set :legacy-mode to "Serializes arg (any Clojure data type) to a byte array. Set :legacy-mode to
true to produce bytes readble by Nippy < 2.x. For custom types extend the true to produce bytes readble by Nippy < 2.x. For custom types extend the
Clojure reader or see `extend-freeze`." Clojure reader or see `extend-freeze`."
^bytes [x & [{:keys [print-dup? password compressor encryptor legacy-mode] ^bytes [x & [{:keys [password compressor encryptor legacy-mode]
:or {print-dup? true :or {compressor snappy-compressor
compressor snappy-compressor
encryptor aes128-encryptor}}]] encryptor aes128-encryptor}}]]
(when legacy-mode (assert-legacy-args compressor password)) (when legacy-mode (assert-legacy-args compressor password))
(let [ba (ByteArrayOutputStream.) (let [ba (ByteArrayOutputStream.)
stream (DataOutputStream. ba)] stream (DataOutputStream. ba)]
(freeze-to-stream! stream x {:print-dup? print-dup?}) (freeze-to-stream! stream x)
(let [ba (.toByteArray ba) (let [ba (.toByteArray ba)
ba (if compressor (compression/compress compressor ba) ba) ba (if compressor (compression/compress compressor ba) ba)
ba (if password (encryption/encrypt encryptor password ba) ba)] ba (if password (encryption/encrypt encryptor password ba) ba)]
@ -468,11 +463,9 @@
(throw (AssertionError. "Only Snappy compressor supported in legacy mode.")))) (throw (AssertionError. "Only Snappy compressor supported in legacy mode."))))
(defn freeze-to-bytes "DEPRECATED: Use `freeze` instead." (defn freeze-to-bytes "DEPRECATED: Use `freeze` instead."
^bytes [x & {:keys [print-dup? compress?] ^bytes [x & {:keys [compress?]
:or {print-dup? true :or {compress? true}}]
compress? true}}]
(freeze x {:legacy-mode true (freeze x {:legacy-mode true
:print-dup? print-dup?
:compressor (when compress? snappy-compressor) :compressor (when compress? snappy-compressor)
:password nil})) :password nil}))

View file

@ -9,7 +9,7 @@
(defmacro bench* [& body] `(utils/bench 10000 (do ~@body) :warmup-laps 2000)) (defmacro bench* [& body] `(utils/bench 10000 (do ~@body) :warmup-laps 2000))
(defn freeze-reader [x] (binding [*print-dup* false] (pr-str x))) (defn freeze-reader [x] (pr-str x))
(defn thaw-reader [x] (edn/read-string x)) (defn thaw-reader [x] (edn/read-string x))
(def roundtrip-reader (comp thaw-reader freeze-reader)) (def roundtrip-reader (comp thaw-reader freeze-reader))