Skip to content

Commit 7593b11

Browse files
committed
Fix cljs.seq-test for :lite-mode
- simple-map-entry: add ICollection impl - RSeq: can use `-count` in lastIndexOf - Vector: Object.indexOf and Object.lastIndexOf inlined, a very small size hit, better for perf - Vector: implement RSeq - Set (Lite): need to return 0 from -count - cljs.seqs-test: elide chunked-seq assertions from lite-mode tests - cljs.lite-test-runner: run cljs.seqs-test
1 parent f6f9a60 commit 7593b11

File tree

3 files changed

+59
-19
lines changed

3 files changed

+59
-19
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,7 @@ reduces them without incurring seq initialization"
17681768
(indexOf [coll x start]
17691769
(-indexOf coll x start))
17701770
(lastIndexOf [coll x]
1771-
(-lastIndexOf coll x (count coll)))
1771+
(-lastIndexOf coll x (-count coll)))
17721772
(lastIndexOf [coll x start]
17731773
(-lastIndexOf coll x start))
17741774

@@ -10396,6 +10396,9 @@ reduces them without incurring seq initialization"
1039610396
(-assoc-n node k v))
1039710397
(-contains-key? [node k]
1039810398
(or (== k 0) (== k 1)))
10399+
ICollection
10400+
(-conj [coll x]
10401+
(Vector. nil #js [k v x] nil))
1039910402
IMapEntry
1040010403
(-key [_] k)
1040110404
(-val [_] v)
@@ -12262,6 +12265,36 @@ reduces them without incurring seq initialization"
1226212265
Object
1226312266
(toString [coll]
1226412267
(pr-str* coll))
12268+
(equiv [coll other]
12269+
(-equiv coll other))
12270+
(indexOf [coll x start]
12271+
(let [start (if (nil? start) 0 start)
12272+
len (-count coll)]
12273+
(if (>= start len)
12274+
-1
12275+
(loop [idx (cond
12276+
(pos? start) start
12277+
(neg? start) (max 0 (+ start len))
12278+
:else start)]
12279+
(if (< idx len)
12280+
(if (= (-nth coll idx) x)
12281+
idx
12282+
(recur (inc idx)))
12283+
-1)))))
12284+
(lastIndexOf [coll x start]
12285+
(let [start (if (nil? start) (alength array) start)
12286+
len (-count coll)]
12287+
(if (zero? len)
12288+
-1
12289+
(loop [idx (cond
12290+
(pos? start) (min (dec len) start)
12291+
(neg? start) (+ len start)
12292+
:else start)]
12293+
(if (>= idx 0)
12294+
(if (= (-nth coll idx) x)
12295+
idx
12296+
(recur (dec idx)))
12297+
-1)))))
1226512298

1226612299
IWithMeta
1226712300
(-with-meta [coll meta] (Vector. meta array __hash))
@@ -12344,10 +12377,15 @@ reduces them without incurring seq initialization"
1234412377
(and (<= 0 k) (< k (alength array)))
1234512378
false))
1234612379

12347-
1234812380
IVector
1234912381
(-assoc-n [coll n val] (-assoc coll n val))
1235012382

12383+
IReversible
12384+
(-rseq [coll]
12385+
(let [cnt (alength array)]
12386+
(when (pos? cnt)
12387+
(RSeq. coll (dec cnt) nil))))
12388+
1235112389
IReduce
1235212390
(-reduce [v f]
1235312391
(array-reduce array f))
@@ -12830,8 +12868,9 @@ reduces them without incurring seq initialization"
1283012868
ICounted
1283112869
(-count [coll]
1283212870
(let [xs (-seq coll)]
12833-
(when (some? xs)
12834-
(-count xs))))
12871+
(if (some? xs)
12872+
(-count xs)
12873+
0)))
1283512874

1283612875
ILookup
1283712876
(-lookup [coll v]

src/test/cljs/cljs/seqs_test.cljs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,21 @@
203203
(is (= (.lastIndexOf (sequence (map inc) '(0 1 0 3 4)) 1) 2))))
204204

205205
(deftest test-chunked
206-
(let [r (range 64)
207-
v (into [] r)]
208-
(testing "Testing Chunked Seqs"
209-
(is (= (hash (seq v)) (hash (seq v))))
210-
(is (= 6 (reduce + (array-chunk (array 1 2 3)))))
211-
(is (instance? ChunkedSeq (seq v)))
212-
(is (= r (seq v)))
213-
(is (= (map inc r) (map inc v)))
214-
(is (= (filter even? r) (filter even? v)))
215-
(is (= (filter odd? r) (filter odd? v)))
216-
(is (= (concat r r r) (concat v v v)))
217-
(is (satisfies? IReduce (seq v)))
218-
(is (== 2010 (reduce + (nnext (nnext (seq v))))))
219-
(is (== 2020 (reduce + 10 (nnext (nnext (seq v)))))))))
206+
(when-not LITE_MODE
207+
(let [r (range 64)
208+
v (into [] r)]
209+
(testing "Testing Chunked Seqs"
210+
(is (= (hash (seq v)) (hash (seq v))))
211+
(is (= 6 (reduce + (array-chunk (array 1 2 3)))))
212+
(is (instance? ChunkedSeq (seq v)))
213+
(is (= r (seq v)))
214+
(is (= (map inc r) (map inc v)))
215+
(is (= (filter even? r) (filter even? v)))
216+
(is (= (filter odd? r) (filter odd? v)))
217+
(is (= (concat r r r) (concat v v v)))
218+
(is (satisfies? IReduce (seq v)))
219+
(is (== 2010 (reduce + (nnext (nnext (seq v))))))
220+
(is (== 2020 (reduce + 10 (nnext (nnext (seq v)))))))))||||)
220221

221222
(deftest test-778
222223
(testing "Testing CLJS-778, -rest, -next RSeq"

src/test/cljs/lite_test_runner.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
'cljs.destructuring-test
7878
'cljs.printing-test
7979
'cljs.new-new-test
80-
#_'cljs.seqs-test ;; rseq Vector
80+
'cljs.seqs-test ;; rseq Vector
8181
#_'cljs.hashing-test
8282
#_'cljs.interop-test ;; ES6 stuff
8383
#_'cljs.iterator-test

0 commit comments

Comments
 (0)