Make coll-thaw, coll-thaw-kvs macros (performance)
This commit is contained in:
parent
9c207cd6af
commit
c5d039b183
1 changed files with 18 additions and 18 deletions
|
|
@ -206,16 +206,16 @@
|
||||||
|
|
||||||
(declare thaw-from-stream)
|
(declare thaw-from-stream)
|
||||||
|
|
||||||
(defn coll-thaw
|
(defmacro ^:private coll-thaw "Thaws simple collection types."
|
||||||
"Thaws simple collection types."
|
[s coll]
|
||||||
[coll ^DataInputStream s]
|
`(let [s# ~s]
|
||||||
(utils/repeatedly-into coll (.readInt s) (thaw-from-stream s)))
|
(utils/repeatedly-into ~coll (.readInt s#) (thaw-from-stream s#))))
|
||||||
|
|
||||||
(defn coll-thaw-kvs
|
(defmacro ^:private coll-thaw-kvs "Thaws key-value collection types."
|
||||||
"Thaws key-value collection types."
|
[s coll]
|
||||||
[coll ^DataInputStream s]
|
`(let [s# ~s]
|
||||||
(utils/repeatedly-into coll (/ (.readInt s) 2)
|
(utils/repeatedly-into ~coll (/ (.readInt s#) 2)
|
||||||
[(thaw-from-stream s) (thaw-from-stream s)]))
|
[(thaw-from-stream s#) (thaw-from-stream s#)])))
|
||||||
|
|
||||||
(defn- thaw-from-stream
|
(defn- thaw-from-stream
|
||||||
[^DataInputStream s]
|
[^DataInputStream s]
|
||||||
|
|
@ -232,15 +232,15 @@
|
||||||
id-string (read-utf8 s)
|
id-string (read-utf8 s)
|
||||||
id-keyword (keyword (read-utf8 s))
|
id-keyword (keyword (read-utf8 s))
|
||||||
|
|
||||||
id-queue (coll-thaw (PersistentQueue/EMPTY) s)
|
id-queue (coll-thaw s (PersistentQueue/EMPTY))
|
||||||
id-sorted-set (coll-thaw (sorted-set) s)
|
id-sorted-set (coll-thaw s (sorted-set))
|
||||||
id-sorted-map (coll-thaw-kvs (sorted-map) s)
|
id-sorted-map (coll-thaw-kvs s (sorted-map))
|
||||||
|
|
||||||
id-list (into '() (rseq (coll-thaw [] s)))
|
id-list (into '() (rseq (coll-thaw s [])))
|
||||||
id-vector (coll-thaw [] s)
|
id-vector (coll-thaw s [])
|
||||||
id-set (coll-thaw #{} s)
|
id-set (coll-thaw s #{})
|
||||||
id-map (coll-thaw-kvs {} s)
|
id-map (coll-thaw-kvs s {})
|
||||||
id-coll (seq (coll-thaw [] s))
|
id-coll (seq (coll-thaw s []))
|
||||||
|
|
||||||
id-meta (let [m (thaw-from-stream s)] (with-meta (thaw-from-stream s) m))
|
id-meta (let [m (thaw-from-stream s)] (with-meta (thaw-from-stream s) m))
|
||||||
|
|
||||||
|
|
@ -261,7 +261,7 @@
|
||||||
id-old-reader (read-string (.readUTF s))
|
id-old-reader (read-string (.readUTF s))
|
||||||
id-old-string (.readUTF s)
|
id-old-string (.readUTF s)
|
||||||
id-old-map (apply hash-map (utils/repeatedly-into []
|
id-old-map (apply hash-map (utils/repeatedly-into []
|
||||||
(* 2 (.readInt s)) (thaw-from-stream s)))
|
(* 2 (.readInt s)) (thaw-from-stream s)))
|
||||||
id-old-keyword (keyword (.readUTF s))
|
id-old-keyword (keyword (.readUTF s))
|
||||||
|
|
||||||
(throw (Exception. (str "Failed to thaw unknown type ID: " type-id))))))
|
(throw (Exception. (str "Failed to thaw unknown type ID: " type-id))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue