Boxed math optimizations

This commit is contained in:
Peter Taoussanis 2015-04-17 19:33:55 +07:00
parent 0e691cbbcf
commit 89e709d5db

View file

@ -209,7 +209,7 @@
(doseq [i# ~'x] (freeze-to-out ~'out i#))) (doseq [i# ~'x] (freeze-to-out ~'out i#)))
(let [bas# (ByteArrayOutputStream.) (let [bas# (ByteArrayOutputStream.)
sout# (DataOutputStream. bas#) sout# (DataOutputStream. bas#)
cnt# (reduce (fn [cnt# i#] cnt# (reduce (fn [^long cnt# i#]
(freeze-to-out sout# i#) (freeze-to-out sout# i#)
(unchecked-inc cnt#)) (unchecked-inc cnt#))
0 ~'x) 0 ~'x)
@ -441,9 +441,11 @@
`(let [in# ~in] (encore/repeatedly-into* ~coll (.readInt in#) (thaw-from-in in#)))) `(let [in# ~in] (encore/repeatedly-into* ~coll (.readInt in#) (thaw-from-in in#))))
(defmacro ^:private read-kvs [in coll] (defmacro ^:private read-kvs [in coll]
`(let [in# ~in] (encore/repeatedly-into* ~coll (/ (.readInt in#) 2) `(let [in# ~in]
(encore/repeatedly-into* ~coll (quot (.readInt in#) 2)
[(thaw-from-in in#) (thaw-from-in in#)]))) [(thaw-from-in in#) (thaw-from-in in#)])))
(declare ^:private custom-readers) (declare ^:private custom-readers)
(defn- read-custom! [type-id in] (defn- read-custom! [type-id in]
(if-let [custom-reader (get @custom-readers type-id)] (if-let [custom-reader (get @custom-readers type-id)]
@ -681,11 +683,11 @@
(defn- coerce-custom-type-id (defn- coerce-custom-type-id
"* +ive byte id -> -ive byte id (for unprefixed custom types). "* +ive byte id -> -ive byte id (for unprefixed custom types).
* Keyword id -> Short hash id (for prefixed custom types)." * Keyword id -> Short hash id (for prefixed custom types)."
[custom-type-id] [^long custom-type-id]
(assert-custom-type-id custom-type-id) (assert-custom-type-id custom-type-id)
(if-not (keyword? custom-type-id) (if-not (keyword? custom-type-id)
(int (- custom-type-id)) (int (- custom-type-id))
(let [hash-id (hash custom-type-id) (let [^long hash-id (hash custom-type-id)
short-hash-id (if (pos? hash-id) short-hash-id (if (pos? hash-id)
(mod hash-id Short/MAX_VALUE) (mod hash-id Short/MAX_VALUE)
(mod hash-id Short/MIN_VALUE))] (mod hash-id Short/MIN_VALUE))]