Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvements on vector/map parsing #28

Merged
merged 2 commits into from
Oct 11, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/msgpack/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,24 @@
(->Ext (.readByte data-input) (read-bytes n data-input))))

(defn- unpack-n [n ^DataInput data-input opts]
(doall (for [_ (range n)] (unpack-stream data-input opts))))
(loop [i 0
v (transient [])]
(if (< i n)
(recur
(unchecked-inc i)
(conj! v (unpack-stream data-input opts)))
(persistent! v))))

(defn- unpack-map [n ^DataInput data-input opts]
(apply hash-map (unpack-n (* 2 n) data-input opts)))
(loop [i 0
m (transient {})]
(if (< i n)
(recur
(unchecked-inc i)
(assoc! m
(unpack-stream data-input opts)
(unpack-stream data-input opts)))
(persistent! m))))

(defn unpack-stream
([^DataInput data-input] (unpack-stream data-input nil))
Expand Down