Micro optimization: read-bytes expansion
This commit is contained in:
parent
7ae954a229
commit
956ce7df7e
1 changed files with 11 additions and 6 deletions
|
|
@ -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?]]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue