Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions src/main/cljs/cljs/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3503,7 +3503,6 @@ reduces them without incurring seq initialization"
:else name)]
(Keyword. ns name (str (when ns (str ns "/")) name) nil))))


(deftype LazySeq [meta ^:mutable fn ^:mutable s ^:mutable __hash]
Object
(toString [coll]
Expand All @@ -3514,10 +3513,7 @@ reduces them without incurring seq initialization"
(if (nil? fn)
s
(do
(loop [ls (fn)]
(if (instance? LazySeq ls)
(recur (.sval ls))
(set! s (seq ls))))
(set! s (fn))
(set! fn nil)
s)))
(indexOf [coll x]
Expand All @@ -3537,27 +3533,27 @@ reduces them without incurring seq initialization"
(-with-meta [coll new-meta]
(if (identical? new-meta meta)
coll
(LazySeq. new-meta #(.sval coll) nil __hash)))
(LazySeq. new-meta #(-seq coll) nil __hash)))

IMeta
(-meta [coll] meta)

ISeq
(-first [coll]
(.sval coll)
(-seq coll)
(when-not (nil? s)
(-first s)))
(first s)))
(-rest [coll]
(.sval coll)
(-seq coll)
(if-not (nil? s)
(-rest s)
(rest s)
()))

INext
(-next [coll]
(.sval coll)
(-seq coll)
(when-not (nil? s)
(-next s)))
(next s)))

ICollection
(-conj [coll o] (cons o coll))
Expand All @@ -3573,7 +3569,14 @@ reduces them without incurring seq initialization"
(-hash [coll] (caching-hash coll hash-ordered-coll __hash))

ISeqable
(-seq [coll] (.sval coll))
(-seq [coll]
(.sval coll)
(when-not (nil? s)
(loop [ls s]
(if (instance? LazySeq ls)
(recur (.sval ls))
(do (set! s ls)
(seq s))))))

IReduce
(-reduce [coll f] (seq-reduce f coll))
Expand Down
6 changes: 5 additions & 1 deletion src/test/cljs/cljs/collections_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,14 +1151,18 @@
(deftest test-cljs-3393
(is (= '(0 2 4) (take 3 (filter even? (range 100000000))))))

(deftest test-cljs-3420-lazy-seq-caching-bug
#_(deftest test-cljs-3420-lazy-seq-caching-bug
(testing "LazySeq should realize seq once"
(let [a (atom 0)
x (eduction (map (fn [_] (swap! a inc))) [nil])
l (lazy-seq x)]
(dotimes [_ 10]
(is (= [1] l))))))

(deftest test-cljs-3240-overflow-regress
(let [things (zipmap (range 15000) (repeat 0))]
(is (zero? (count (filter #(-> % key string?) things))))))

(comment

(run-tests)
Expand Down