Micro optimization: read-bytes expansion

This commit is contained in:
Peter Taoussanis 2015-09-28 10:21:15 +07:00
parent 7ae954a229
commit 956ce7df7e

View file

@ -435,12 +435,17 @@
(declare thaw-from-in) (declare thaw-from-in)
(defmacro read-bytes [in & [small?]] (defmacro read-bytes [in & [small?]]
`(let [in# ~in (if small? ; Optimization, must be known before id's written
size# (if ~small? ; Optimization, must be known before id's written `(let [in# ~in
(.readByte in#) size# (.readByte in#)
(.readInt in#)) ba# (byte-array size#)]
ba# (byte-array size#)] (.readFully in# ba# 0 size#)
(.readFully in# ba# 0 size#) ba#)) ba#)
`(let [in# ~in
size# (.readInt in#)
ba# (byte-array size#)]
(.readFully in# ba# 0 size#)
ba#)))
(defmacro read-biginteger [in] `(BigInteger. (read-bytes ~in))) (defmacro read-biginteger [in] `(BigInteger. (read-bytes ~in)))
(defmacro read-utf8 [in & [small?]] (defmacro read-utf8 [in & [small?]]