Skip to content

Commit

Permalink
CLJS-461: preserve metadata on automatic map conversions
Browse files Browse the repository at this point in the history
Also includes basic tests based on the failing form from the ticket.
  • Loading branch information
michalmarczyk authored and swannodette committed Jan 27, 2013
1 parent 306ff22 commit 3ed16f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/cljs/cljs/core.cljs
Expand Up @@ -3597,13 +3597,13 @@ reduces them without incurring seq initialization"
(let [ks (.-keys m)
len (alength ks)
so (.-strobj m)
out (with-meta cljs.core.PersistentHashMap/EMPTY (meta m))]
mm (meta m)]
(loop [i 0
out (transient out)]
out (transient cljs.core.PersistentHashMap/EMPTY)]
(if (< i len)
(let [k (aget ks i)]
(recur (inc i) (assoc! out k (aget so k))))
(persistent! (assoc! out k v))))))
(with-meta (persistent! (assoc! out k v)) mm)))))

;;; ObjMap

Expand Down Expand Up @@ -3912,10 +3912,9 @@ reduces them without incurring seq initialization"
(.push k)
(.push v))
nil)
(persistent!
(assoc!
(transient (into cljs.core.PersistentHashMap/EMPTY coll))
k v)))
(with-meta
(assoc (into cljs.core.PersistentHashMap/EMPTY coll) k v)
meta))

(identical? v (aget arr (inc idx)))
coll
Expand Down
14 changes: 14 additions & 0 deletions test/cljs/cljs/core_test.cljs
Expand Up @@ -1262,6 +1262,20 @@
(assert (= (count m1) 100))
(assert (= (count m2) 100)))))

;; CLJS-461: automatic map conversions
(loop [i 0 m (with-meta {} {:foo :bar}) result []]
(if (<= i (+ cljs.core.ObjMap/HASHMAP_THRESHOLD 2))
(recur (inc i) (assoc m (str i) i) (conj result (meta m)))
(let [n (inc (+ cljs.core.ObjMap/HASHMAP_THRESHOLD 2))
expected (repeat n {:foo :bar})]
(assert (= result expected)))))
(loop [i 0 m (with-meta {-1 :quux} {:foo :bar}) result []]
(if (<= i (+ cljs.core.PersistentArrayMap/HASHMAP_THRESHOLD 2))
(recur (inc i) (assoc m i i) (conj result (meta m)))
(let [n (inc (+ cljs.core.PersistentArrayMap/HASHMAP_THRESHOLD 2))
expected (repeat n {:foo :bar})]
(assert (= result expected)))))

;; TransientHashSet
(loop [s (transient #{})
i 0]
Expand Down

0 comments on commit 3ed16f3

Please sign in to comment.