Commits

Ning Sun committed ba00f8f

use transient data structure in loop

Comments (0)

Files changed (1)

src/geohash/core.clj

 
 (defn- do-decode-hashcode
   [bits hash-code geocode-data]
-  (loop [bits 4 geocode-data geocode-data]
-    (if (< bits 0) geocode-data
+  (loop [bits 4 geocode-data (transient (into {} geocode-data))]
+    (if (< bits 0) (persistent! geocode-data)
       (if (true? (:islon geocode-data))
         (let [
               bit (bit-and (bit-shift-right hash-code bits) 1)
               minlon (if (= bit 1) mid (:minlon geocode-data))
               maxlon (if (= bit 1) (:maxlon geocode-data) mid)]
           (recur (dec bits)
-            (assoc geocode-data
+            (assoc! geocode-data
               :minlon minlon
               :maxlon maxlon
               :islon (not (:islon geocode-data)))))
               minlat (if (= bit 1) mid (:minlat geocode-data))
               maxlat (if (= bit 1) (:maxlat geocode-data) mid)]
           (recur (dec bits)
-            (assoc geocode-data
+            (assoc! geocode-data
               :minlat minlat
               :maxlat maxlat
               :islon (not (:islon geocode-data)))))))))
   (let [
         hashcodes (map base32-index hashstring)
         bbox (do-decode-bbox hashcodes (struct geocode-data 180.0 -180.0 90.0 -90.0 true nil nil nil))]
-    (dissoc (hash-map geocode-data)
+    (dissoc (into {} geocode-data)
       :islon
       :bits
       :hashcode