Micro optimization: remove & args
This commit is contained in:
parent
53d993e132
commit
7ae954a229
1 changed files with 93 additions and 96 deletions
|
|
@ -366,7 +366,7 @@
|
||||||
|
|
||||||
(defn freeze-to-out!
|
(defn freeze-to-out!
|
||||||
"Low-level API. Serializes arg (any Clojure data type) to a DataOutput."
|
"Low-level API. Serializes arg (any Clojure data type) to a DataOutput."
|
||||||
[^DataOutput data-output x & _]
|
[^DataOutput data-output x]
|
||||||
(freeze-to-out data-output x))
|
(freeze-to-out data-output x))
|
||||||
|
|
||||||
(defn default-freeze-compressor-selector
|
(defn default-freeze-compressor-selector
|
||||||
|
|
@ -394,10 +394,11 @@
|
||||||
(defn freeze
|
(defn freeze
|
||||||
"Serializes arg (any Clojure data type) to a byte array. To freeze custom
|
"Serializes arg (any Clojure data type) to a byte array. To freeze custom
|
||||||
types, extend the Clojure reader or see `extend-freeze`."
|
types, extend the Clojure reader or see `extend-freeze`."
|
||||||
^bytes [x & [{:keys [compressor encryptor password skip-header?]
|
(^bytes [x] (freeze x nil))
|
||||||
|
(^bytes [x {:keys [compressor encryptor password skip-header?]
|
||||||
:or {compressor :auto
|
:or {compressor :auto
|
||||||
encryptor aes128-encryptor}
|
encryptor aes128-encryptor}
|
||||||
:as opts}]]
|
:as opts}]
|
||||||
(let [legacy-mode? (:legacy-mode opts) ; DEPRECATED Nippy v1-compatible freeze
|
(let [legacy-mode? (:legacy-mode opts) ; DEPRECATED Nippy v1-compatible freeze
|
||||||
compressor (if legacy-mode? snappy-compressor compressor)
|
compressor (if legacy-mode? snappy-compressor compressor)
|
||||||
encryptor (when password (if-not legacy-mode? encryptor nil))
|
encryptor (when password (if-not legacy-mode? encryptor nil))
|
||||||
|
|
@ -427,7 +428,7 @@
|
||||||
(compression/header-id c)) :else))
|
(compression/header-id c)) :else))
|
||||||
:encryptor-id (when-let [e encryptor]
|
:encryptor-id (when-let [e encryptor]
|
||||||
(or (encryption/standard-header-ids
|
(or (encryption/standard-header-ids
|
||||||
(encryption/header-id e)) :else))})))))
|
(encryption/header-id e)) :else))}))))))
|
||||||
|
|
||||||
;;;; Thawing
|
;;;; Thawing
|
||||||
|
|
||||||
|
|
@ -597,7 +598,7 @@
|
||||||
(defn thaw-from-in!
|
(defn thaw-from-in!
|
||||||
"Low-level API. Deserializes a frozen object from given DataInput to its
|
"Low-level API. Deserializes a frozen object from given DataInput to its
|
||||||
original Clojure data type."
|
original Clojure data type."
|
||||||
[data-input & _]
|
[data-input]
|
||||||
(thaw-from-in data-input))
|
(thaw-from-in data-input))
|
||||||
|
|
||||||
(defn- try-parse-header [ba]
|
(defn- try-parse-header [ba]
|
||||||
|
|
@ -634,16 +635,17 @@
|
||||||
Options include:
|
Options include:
|
||||||
:compressor - An ICompressor, :auto (requires Nippy header), or nil.
|
:compressor - An ICompressor, :auto (requires Nippy header), or nil.
|
||||||
:encryptor - An IEncryptor, :auto (requires Nippy header), or nil."
|
:encryptor - An IEncryptor, :auto (requires Nippy header), or nil."
|
||||||
[^bytes ba
|
|
||||||
& [{:keys [compressor encryptor password v1-compatibility?]
|
|
||||||
:or {compressor :auto
|
|
||||||
encryptor :auto
|
|
||||||
v1-compatibility? true ; Recommend disabling when possible
|
|
||||||
}
|
|
||||||
:as opts}]]
|
|
||||||
|
|
||||||
(assert (not (contains? opts :headerless-meta))
|
([ba] (thaw ba nil))
|
||||||
":headerless-meta `thaw` option removed as of Nippy v2.7.")
|
([^bytes ba
|
||||||
|
{:keys [v1-compatibility? compressor encryptor password]
|
||||||
|
:or {v1-compatibility? true ; Recommend disabling when possible
|
||||||
|
compressor :auto
|
||||||
|
encryptor :auto}
|
||||||
|
:as opts}]
|
||||||
|
|
||||||
|
(assert (not (:headerless-meta opts))
|
||||||
|
":headerless-meta `thaw` opt removed in Nippy v2.7+")
|
||||||
|
|
||||||
(let [ex (fn [msg & [e]] (throw (ex-info (format "Thaw failed: %s" msg)
|
(let [ex (fn [msg & [e]] (throw (ex-info (format "Thaw failed: %s" msg)
|
||||||
{:opts (merge opts
|
{:opts (merge opts
|
||||||
|
|
@ -700,7 +702,7 @@
|
||||||
;; Well-formed header definitely not present
|
;; Well-formed header definitely not present
|
||||||
(try (thaw-nippy-v1-data ba)
|
(try (thaw-nippy-v1-data ba)
|
||||||
(catch Exception _
|
(catch Exception _
|
||||||
(thaw-data ba :no-header :no-header))))))
|
(thaw-data ba :no-header :no-header)))))))
|
||||||
|
|
||||||
(comment (thaw (freeze "hello"))
|
(comment (thaw (freeze "hello"))
|
||||||
(thaw (freeze "hello" {:compressor nil}))
|
(thaw (freeze "hello" {:compressor nil}))
|
||||||
|
|
@ -912,8 +914,3 @@
|
||||||
|
|
||||||
(comment (inspect-ba (freeze "hello"))
|
(comment (inspect-ba (freeze "hello"))
|
||||||
(seq (:data-ba (inspect-ba (freeze "hello")))))
|
(seq (:data-ba (inspect-ba (freeze "hello")))))
|
||||||
|
|
||||||
;;;; Deprecated API
|
|
||||||
|
|
||||||
(def freeze-to-stream! "DEPRECATED: Use `freeze-to-out!` instead." freeze-to-out!)
|
|
||||||
(def thaw-from-stream! "DEPRECATED: Use `thaw-from-in!` instead." thaw-from-in!)
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue