Perf: fix boxed math on long compression

This commit is contained in:
Peter Taoussanis 2015-09-14 12:52:35 +07:00
parent d89649deeb
commit 56b33e23f0

View file

@ -279,24 +279,25 @@
(write-utf8 out (.getName (class x))) ; Reflect (write-utf8 out (.getName (class x))) ; Reflect
(freeze-to-out out (into {} x))) (freeze-to-out out (into {} x)))
(freezer Byte id-byte (.writeByte out x)) (freezer Byte id-byte (.writeByte out x))
(freezer Short id-short (.writeShort out x)) (freezer Short id-short (.writeShort out x))
(freezer Integer id-integer (.writeInt out x)) (freezer Integer id-integer (.writeInt out x))
;;(freezer Long id-long (.writeLong out x)) ;;(freezer Long id-long (.writeLong out x))
(extend-type Long ; Optimized common-case type (extend-type Long ; Optimized common-case type
Freezable Freezable
(freeze-to-out* [x ^DataOutput out] (freeze-to-out* [x ^DataOutput out]
(cond (let [^long x x]
(<= Byte/MIN_VALUE x Byte/MAX_VALUE) (cond
(do (write-id out id-byte-as-long) (.writeByte out x)) (and (<= Byte/MIN_VALUE x) (<= x Byte/MAX_VALUE))
(do (write-id out id-byte-as-long) (.writeByte out x))
(<= Short/MIN_VALUE x Short/MAX_VALUE) (and (<= Short/MIN_VALUE x) (<= x Short/MAX_VALUE))
(do (write-id out id-short-as-long) (.writeShort out x)) (do (write-id out id-short-as-long) (.writeShort out x))
(<= Integer/MIN_VALUE x Integer/MAX_VALUE) (and (<= Integer/MIN_VALUE x) (<= x Integer/MAX_VALUE))
(do (write-id out id-int-as-long) (.writeInt out x)) (do (write-id out id-int-as-long) (.writeInt out x))
:else (do (write-id out id-long) (.writeLong out x))))) :else (do (write-id out id-long) (.writeLong out x))))))
;; ;;
@ -361,6 +362,7 @@
(defn- wrap-header [data-ba head-meta] (defn- wrap-header [data-ba head-meta]
(if-let [head-ba (get-head-ba head-meta)] (if-let [head-ba (get-head-ba head-meta)]
;; TODO Would be nice if we could avoid the array copy here:
(encore/ba-concat head-ba data-ba) (encore/ba-concat head-ba data-ba)
(throw (ex-info (format "Unrecognized header meta: %s" head-meta) (throw (ex-info (format "Unrecognized header meta: %s" head-meta)
{:head-meta head-meta})))) {:head-meta head-meta}))))