[#104] Micro-optimization: remove unnecessary runtime 'if' in extend-freeze macro (@scramjet)

This commit is contained in:
Peter Taoussanis 2017-12-21 10:08:24 +01:00
parent 1a8a44286a
commit 2272d5ea57

View file

@ -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)
`(extend-type ~type IFreezable1 (let [write-id-form
(~'-freeze-without-meta! [~x ~(with-meta out {:tag 'java.io.DataOutput})] (if (keyword? custom-type-id)
(if-not ~(keyword? custom-type-id) ;; Prefixed [const byte id][cust hash id][payload]:
;; Unprefixed [cust byte id][payload]: `(do (write-id ~out ~id-prefixed-custom)
(write-id ~out ~(coerce-custom-type-id custom-type-id)) (.writeShort ~out ~(coerce-custom-type-id custom-type-id)))
;; Prefixed [const byte id][cust hash id][payload]: ;; Unprefixed [cust byte id][payload]:
(do (write-id ~out ~id-prefixed-custom) `(write-id ~out ~(coerce-custom-type-id custom-type-id)))]
(.writeShort ~out ~(coerce-custom-type-id custom-type-id))))
~@body))) `(extend-type ~type IFreezable1
(~'-freeze-without-meta! [~x ~(with-meta out {:tag 'java.io.DataOutput})]
~write-id-form
~@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: