Permalink
Browse files

CLJS-725: fix broken optimizations around IndexedSeq

collection construction optimizations around IndexedSeq not checking for
zero index
  • Loading branch information...
1 parent de6ee41 commit 8943faf94856ea706252fa3276ad8ded234595f2 @swannodette swannodette committed Dec 11, 2013
Showing with 9 additions and 3 deletions.
  1. +3 −3 src/cljs/cljs/core.cljs
  2. +6 −0 test/cljs/cljs/core_test.cljs
View
@@ -1976,7 +1976,7 @@ reduces them without incurring seq initialization"
(reduce conj () coll)))
(defn list [& xs]
- (let [arr (if (instance? IndexedSeq xs)
+ (let [arr (if (and (instance? IndexedSeq xs) (zero? (.-i xs)))
(.-arr xs)
(let [arr (array)]
(loop [^not-native xs xs]
@@ -3389,7 +3389,7 @@ reduces them without incurring seq initialization"
coll)))
(defn vector [& args]
- (if (instance? IndexedSeq args)
+ (if (and (instance? IndexedSeq args) (zero? (.-i args)))
(cljs.core.PersistentVector.fromArray (.-arr args) true)
(vec args)))
@@ -6248,7 +6248,7 @@ reduces them without incurring seq initialization"
(cond
(nil? in) #{}
- (instance? IndexedSeq in)
+ (and (instance? IndexedSeq in) (zero? (.-i in)))
(set-from-indexed-seq in)
:else
@@ -2027,5 +2027,11 @@
(assert (array? (aget #js {"foo" #js [1 2 3]} "foo")))
(assert (= (seq (aget #js {"foo" #js [1 2 3]} "foo")) '(1 2 3)))
+ ;; CLJS-725
+
+ (assert (= (apply vector (drop-while (partial = 1) [1 2 3])) [2 3]))
+ (assert (= (apply list (drop-while (partial = 1) [1 2 3])) '(2 3)))
+ (assert (= (set (drop 1 #js [1 2 3])) #{2 3}))
+
:ok
)

0 comments on commit 8943faf

Please sign in to comment.