optimize type range checks in freeze-to-out* (10x faster)

This commit is contained in:
Karsten Schmidt 2015-09-15 14:17:03 +01:00
parent 140171393c
commit f2f8b419b1

View file

@ -292,13 +292,13 @@
Freezable Freezable
(freeze-to-out* [x ^DataOutput out] (freeze-to-out* [x ^DataOutput out]
(cond (cond
(<= Byte/MIN_VALUE x Byte/MAX_VALUE) (and (<= Byte/MIN_VALUE x) (<= x Byte/MAX_VALUE))
(do (write-id out id-byte-as-long) (.writeByte out x)) (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)))))