[#104] Micro-optimization: remove unnecessary runtime 'if' in extend-freeze macro (@scramjet)
This commit is contained in:
parent
1a8a44286a
commit
2272d5ea57
1 changed files with 12 additions and 9 deletions
|
|
@ -1426,15 +1426,18 @@
|
||||||
(.writeUTF [data-output] (:data x)))"
|
(.writeUTF [data-output] (:data x)))"
|
||||||
[type custom-type-id [x out] & body]
|
[type custom-type-id [x out] & body]
|
||||||
(assert-custom-type-id custom-type-id)
|
(assert-custom-type-id custom-type-id)
|
||||||
|
(let [write-id-form
|
||||||
|
(if (keyword? custom-type-id)
|
||||||
|
;; Prefixed [const byte id][cust hash id][payload]:
|
||||||
|
`(do (write-id ~out ~id-prefixed-custom)
|
||||||
|
(.writeShort ~out ~(coerce-custom-type-id custom-type-id)))
|
||||||
|
;; Unprefixed [cust byte id][payload]:
|
||||||
|
`(write-id ~out ~(coerce-custom-type-id custom-type-id)))]
|
||||||
|
|
||||||
`(extend-type ~type IFreezable1
|
`(extend-type ~type IFreezable1
|
||||||
(~'-freeze-without-meta! [~x ~(with-meta out {:tag 'java.io.DataOutput})]
|
(~'-freeze-without-meta! [~x ~(with-meta out {:tag 'java.io.DataOutput})]
|
||||||
(if-not ~(keyword? custom-type-id)
|
~write-id-form
|
||||||
;; Unprefixed [cust byte id][payload]:
|
~@body))))
|
||||||
(write-id ~out ~(coerce-custom-type-id custom-type-id))
|
|
||||||
;; Prefixed [const byte id][cust hash id][payload]:
|
|
||||||
(do (write-id ~out ~id-prefixed-custom)
|
|
||||||
(.writeShort ~out ~(coerce-custom-type-id custom-type-id))))
|
|
||||||
~@body)))
|
|
||||||
|
|
||||||
(defmacro extend-thaw
|
(defmacro extend-thaw
|
||||||
"Extends Nippy to support thawing of a custom type with given id:
|
"Extends Nippy to support thawing of a custom type with given id:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue