From 89e709d5db018b07a3877b0f11e5266d9e9b68e4 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Fri, 17 Apr 2015 19:33:55 +0700 Subject: [PATCH] Boxed math optimizations --- src/taoensso/nippy.clj | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/taoensso/nippy.clj b/src/taoensso/nippy.clj index 3b20290..78658ef 100644 --- a/src/taoensso/nippy.clj +++ b/src/taoensso/nippy.clj @@ -209,7 +209,7 @@ (doseq [i# ~'x] (freeze-to-out ~'out i#))) (let [bas# (ByteArrayOutputStream.) sout# (DataOutputStream. bas#) - cnt# (reduce (fn [cnt# i#] + cnt# (reduce (fn [^long cnt# i#] (freeze-to-out sout# i#) (unchecked-inc cnt#)) 0 ~'x) @@ -441,8 +441,10 @@ `(let [in# ~in] (encore/repeatedly-into* ~coll (.readInt in#) (thaw-from-in in#)))) (defmacro ^:private read-kvs [in coll] - `(let [in# ~in] (encore/repeatedly-into* ~coll (/ (.readInt in#) 2) - [(thaw-from-in in#) (thaw-from-in in#)]))) + `(let [in# ~in] + (encore/repeatedly-into* ~coll (quot (.readInt in#) 2) + [(thaw-from-in in#) (thaw-from-in in#)]))) + (declare ^:private custom-readers) (defn- read-custom! [type-id in] @@ -681,11 +683,11 @@ (defn- coerce-custom-type-id "* +ive byte id -> -ive byte id (for unprefixed 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) (if-not (keyword? 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) (mod hash-id Short/MAX_VALUE) (mod hash-id Short/MIN_VALUE))]