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?]]
(if small? ; Optimization, must be known before id's written
`(let [in# ~in `(let [in# ~in
size# (if ~small? ; Optimization, must be known before id's written size# (.readByte in#)
(.readByte in#)
(.readInt in#))
ba# (byte-array size#)] ba# (byte-array size#)]
(.readFully in# ba# 0 size#) ba#)) (.readFully in# ba# 0 size#)
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?]]