File tree 2 files changed +21
-17
lines changed
2 files changed +21
-17
lines changed Original file line number Diff line number Diff line change @@ -3514,7 +3514,10 @@ reduces them without incurring seq initialization"
3514
3514
(if (nil? fn )
3515
3515
s
3516
3516
(do
3517
- (set! s (fn ))
3517
+ (loop [ls (fn )]
3518
+ (if (instance? LazySeq ls)
3519
+ (recur (.sval ls))
3520
+ (set! s (seq ls))))
3518
3521
(set! fn nil )
3519
3522
s)))
3520
3523
(indexOf [coll x]
@@ -3534,27 +3537,27 @@ reduces them without incurring seq initialization"
3534
3537
(-with-meta [coll new-meta]
3535
3538
(if (identical? new-meta meta)
3536
3539
coll
3537
- (LazySeq. new-meta #(-seq coll) nil __hash)))
3540
+ (LazySeq. new-meta #(.sval coll) nil __hash)))
3538
3541
3539
3542
IMeta
3540
3543
(-meta [coll] meta)
3541
3544
3542
3545
ISeq
3543
3546
(-first [coll]
3544
- (-seq coll)
3547
+ (.sval coll)
3545
3548
(when-not (nil? s)
3546
- (first s)))
3549
+ (- first s)))
3547
3550
(-rest [coll]
3548
- (-seq coll)
3551
+ (.sval coll)
3549
3552
(if-not (nil? s)
3550
- (rest s)
3553
+ (- rest s)
3551
3554
()))
3552
3555
3553
3556
INext
3554
3557
(-next [coll]
3555
- (-seq coll)
3558
+ (.sval coll)
3556
3559
(when-not (nil? s)
3557
- (next s)))
3560
+ (- next s)))
3558
3561
3559
3562
ICollection
3560
3563
(-conj [coll o] (cons o coll))
@@ -3570,14 +3573,7 @@ reduces them without incurring seq initialization"
3570
3573
(-hash [coll] (caching-hash coll hash-ordered-coll __hash))
3571
3574
3572
3575
ISeqable
3573
- (-seq [coll]
3574
- (.sval coll)
3575
- (when-not (nil? s)
3576
- (loop [ls s]
3577
- (if (instance? LazySeq ls)
3578
- (recur (.sval ls))
3579
- (do (set! s ls)
3580
- (seq s))))))
3576
+ (-seq [coll] (.sval coll))
3581
3577
3582
3578
IReduce
3583
3579
(-reduce [coll f] (seq-reduce f coll))
@@ -7216,7 +7212,7 @@ reduces them without incurring seq initialization"
7216
7212
extra-kvs (seq trailing)
7217
7213
ret (make-array (+ seed-cnt (* 2 (count extra-kvs))))
7218
7214
ret (array-copy seed 0 ret 0 seed-cnt)]
7219
- (loop [i seed-cnt extra-kvs extra-kvs]
7215
+ (loop [i seed-cnt extra-kvs extra-kvs]00
7220
7216
(if extra-kvs
7221
7217
(let [kv (first extra-kvs)]
7222
7218
(aset ret i (-key kv))
Original file line number Diff line number Diff line change 1151
1151
(deftest test-cljs-3393
1152
1152
(is (= '(0 2 4 ) (take 3 (filter even? (range 100000000 ))))))
1153
1153
1154
+ (deftest test-cljs-3420-lazy-seq-caching-bug
1155
+ (testing " LazySeq should realize seq once"
1156
+ (let [a (atom 0 )
1157
+ x (eduction (map (fn [_] (swap! a inc))) [nil ])
1158
+ l (lazy-seq x)]
1159
+ (dotimes [_ 10 ]
1160
+ (is (= [1 ] l))))))
1161
+
1154
1162
(comment
1155
1163
1156
1164
(run-tests )
You can’t perform that action at this time.
0 commit comments