Make coll-thaw, coll-thaw-kvs macros (performance)

This commit is contained in:
Peter Taoussanis 2013-06-16 12:44:42 +07:00
parent 9c207cd6af
commit c5d039b183

View file

@ -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))