Skip to content

Commit 0c0602a

Browse files
tonskyswannodette
authored andcommitted
CLJS-1199 array-map should skip dropped elements of IndexedSeq
1 parent 3cf142c commit 0c0602a

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/cljs/cljs/core.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7448,7 +7448,7 @@ reduces them without incurring seq initialization"
74487448
"keyval => key val
74497449
Returns a new array map with supplied mappings."
74507450
[& keyvals]
7451-
(let [arr (if (instance? IndexedSeq keyvals)
7451+
(let [arr (if (and (instance? IndexedSeq keyvals) (zero? (.-i keyvals)))
74527452
(.-arr keyvals)
74537453
(into-array keyvals))]
74547454
(.fromArray cljs.core/PersistentArrayMap arr true false)))

test/cljs/cljs/core_test.cljs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,7 +2686,7 @@
26862686
(defn foo-set [x]
26872687
(first x))
26882688

2689-
(deftest test-cljs-982-var-deref []
2689+
(deftest test-cljs-982-var-deref
26902690
(let [f (foo-var #'foo-set)]
26912691
(is (= (f [1 2 3]) 1))
26922692
(set! foo-set (fn [x] :oops))
@@ -2731,17 +2731,21 @@
27312731
:foo #'foo-1187
27322732
:bar #'bar-1187) []))
27332733

2734-
(deftest test-cljs-1187 []
2734+
(deftest test-cljs-1187
27352735
(testing "Internal var nodes analyzed in expression context"
27362736
(is (= (with-out-str (print-foo-1187 :foo))
27372737
"foo!"))))
27382738

2739-
(deftest test-cljs-1189 []
2739+
(deftest test-cljs-1189
27402740
(testing "array-map should always return array maps"
27412741
(let [am (apply array-map (range 100))]
27422742
(is (== (count am) 50))
27432743
(is (instance? PersistentArrayMap am)))))
27442744

2745+
(deftest test-cljs-1199
2746+
(testing "array-map should skip dropped elements of IndexedSeq"
2747+
(is (= {:a 1} (apply array-map (drop 1 [0 :a 1]))))))
2748+
27452749
(comment
27462750
;; ObjMap
27472751
;; (let [ks (map (partial str "foo") (range 500))

0 commit comments

Comments
 (0)