File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -5534,9 +5534,13 @@ reduces them without incurring seq initialization"
5534
5534
5535
5535
IReduce
5536
5536
(-reduce [coll f]
5537
- (pv-reduce v f start end))
5537
+ (if (implements? APersistentVector v)
5538
+ (pv-reduce v f start end)
5539
+ (ci-reduce coll f)))
5538
5540
(-reduce [coll f init]
5539
- (pv-reduce v f init start end))
5541
+ (if (implements? APersistentVector v)
5542
+ (pv-reduce v f init start end)
5543
+ (ci-reduce coll f init)))
5540
5544
5541
5545
IKVReduce
5542
5546
(-kv-reduce [coll f init]
Original file line number Diff line number Diff line change 660
660
(is (= metadata (meta k'))))
661
661
(let [map (sorted-map nil :foo )]
662
662
(is (= (find map nil ) [nil :foo ])))))
663
+
664
+ (deftype CustomVectorThing [v]
665
+ IVector
666
+ (-assoc-n [coll i val] (assoc-n v i val))
667
+
668
+ IIndexed
669
+ (-nth [coll i] (nth v i))
670
+ (-nth [coll i not-found] (nth v i not-found))
671
+
672
+ ICounted
673
+ (-count [coll] (count v)))
674
+
675
+ (deftest test-cljs-2128
676
+ (testing " Subvec iteration"
677
+ (testing " Subvec over PersistentVector uses RangedIterator"
678
+ (is (instance? RangedIterator (-iterator (subvec [0 1 2 3 ] 1 3 )))))
679
+ (testing " Subvec over other vectors uses naive SeqIter"
680
+ (is (instance? SeqIter (-iterator (subvec (->CustomVectorThing [0 1 2 3 ]) 1 3 ))))))
681
+ (testing " Subvec reduce"
682
+ (testing " Subvec over PersistentVector reduces as expected"
683
+ (is (= [1 2 ] (reduce conj [] (subvec [0 1 2 3 ] 1 3 )))))
684
+ (testing " Subvec over other vectors reduces as expected"
685
+ (is (= [1 2 ] (reduce conj [] (subvec (->CustomVectorThing [0 1 2 3 ]) 1 3 )))))))
You can’t perform that action at this time.
0 commit comments