From 9cac0afb983e5153a61add603a1a3483421857ed Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Fri, 11 Sep 2020 10:22:31 +0200 Subject: [PATCH] Misc housekeeping --- src/taoensso/nippy.clj | 20 +++++++++----------- test/taoensso/nippy/tests/main.clj | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/taoensso/nippy.clj b/src/taoensso/nippy.clj index ffa27ff..015e299 100644 --- a/src/taoensso/nippy.clj +++ b/src/taoensso/nippy.clj @@ -35,8 +35,6 @@ ;;;; TODO ;; - Performance would benefit from ^:static support / direct linking / etc. -;; - Auto cache keywords? When map keys? Configurable? Per-map -;; (`cache-keys`)? Just rely on compression? ;;;; Nippy data format ;; * 4-byte header (Nippy v2.x+) (may be disabled but incl. by default) [1] @@ -282,10 +280,6 @@ (enc/defonce ^:dynamic *incl-metadata?* "Include metadata when freezing/thawing?" true) -(defn set-freeze-fallback! [x] (alter-var-root #'*freeze-fallback* (constantly x))) -(defn set-auto-freeze-compressor! [x] (alter-var-root #'*auto-freeze-compressor* (constantly x))) -(defn swap-custom-readers! [f] (alter-var-root #'*custom-readers* f)) - ;;;; Java Serializable config ;; Unfortunately quite a bit of complexity to do this safely @@ -1829,7 +1823,7 @@ (when (contains? *custom-readers* ~(coerce-custom-type-id custom-type-id)) (println (str "Warning: resetting Nippy thaw for custom type with id: " ~custom-type-id))) - (swap-custom-readers! + (alter-var-root #'*custom-readers* (fn [m#] (assoc m# ~(coerce-custom-type-id custom-type-id) @@ -1846,9 +1840,9 @@ ;;;; Stress data (defrecord StressRecord [data]) -(deftype StressType [data] - Object - (equals [a b] (= (.-data a) (.-data ^StressType b)))) +(deftype StressType [data] + Object (equals [a b] (= (.-data a) (.-data ^StressType b)))) + (def stress-data "Reference data used for tests & benchmarks" {:bytes (byte-array [(byte 1) (byte 2) (byte 3)]) :nil nil @@ -2010,4 +2004,8 @@ ;;;; Deprecated -(enc/deprecated (def freeze-fallback-as-str "DEPRECATED" write-unfreezable)) +(enc/deprecated + (def freeze-fallback-as-str "DEPRECATED, use `write-unfreezable`" write-unfreezable) + (defn set-freeze-fallback! "DEPRECATED, just use `alter-var-root`" [x] (alter-var-root #'*freeze-fallback* (constantly x))) + (defn set-auto-freeze-compressor! "DEPRECATED, just use `alter-var-root`" [x] (alter-var-root #'*auto-freeze-compressor* (constantly x))) + (defn swap-custom-readers! "DEPRECATED, just use `alter-var-root`" [f] (alter-var-root #'*custom-readers* f))) diff --git a/test/taoensso/nippy/tests/main.clj b/test/taoensso/nippy/tests/main.clj index a443b61..08d07b9 100644 --- a/test/taoensso/nippy/tests/main.clj +++ b/test/taoensso/nippy/tests/main.clj @@ -92,7 +92,7 @@ (deftest _types ;;; Extend to custom Type (is (thrown? Exception ; No thaw extension yet - (do (nippy/swap-custom-readers! (constantly {})) + (do (alter-var-root #'nippy/*custom-readers* (constantly {})) (nippy/extend-freeze MyType 1 [x s] (.writeUTF s (.data x))) (thaw (freeze (MyType. "val")))))) (is (do (nippy/extend-thaw 1 [s] (MyType. (.readUTF s)))