Skip to content
Open
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
50 changes: 48 additions & 2 deletions src/main/cljs/cljs/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5677,6 +5677,37 @@ reduces them without incurring seq initialization"
(defprotocol APersistentVector
"Marker protocol")

(defn- ^boolean pv-arr-range-eq
[a off-a b off-b len]
(loop [j 0]
(if (< j len)
(let [x (aget a (+ off-a j))
y (aget b (+ off-b j))]
(if (= x y)
(recur (unchecked-inc j))
false))
true)))

(defn- ^boolean pv-range-eq*
[a ia b ib cnt-a]
(loop [ra cnt-a
ia ia
ib ib]
(if (zero? ra)
true
(let [arr-a (unchecked-array-for a ia)
arr-b (unchecked-array-for b ib)
off-a (bit-and ia 0x1f)
off-b (bit-and ib 0x1f)
rem-a (- 32 off-a)
rem-b (- 32 off-b)
m (min rem-a rem-b)
len (min ra m)]
(if (or (identical? arr-a arr-b)
(pv-arr-range-eq arr-a off-a arr-b off-b len))
(recur (- ra len) (+ ia len) (+ ib len))
false)))))

(deftype PersistentVector [meta cnt shift root tail ^:mutable __hash]
Object
(toString [coll]
Expand Down Expand Up @@ -5747,7 +5778,8 @@ reduces them without incurring seq initialization"
ISequential
IEquiv
(-equiv [coll other]
(if (instance? PersistentVector other)
(cond
(instance? PersistentVector other)
(if (== cnt (count other))
(let [me-iter (-iterator coll)
you-iter (-iterator other)]
Expand All @@ -5760,6 +5792,17 @@ reduces them without incurring seq initialization"
false))
true)))
false)

(and (instance? ChunkedSeq other)
(instance? PersistentVector (.-vec other)))
(let [v (.-vec other)
iother (+ (.-i other) (.-off other))
ra (- (.-cnt v) iother)]
(if (== cnt ra)
(pv-range-eq* coll 0 v iother cnt)
false))

:else
(equiv-sequential coll other)))

IHash
Expand Down Expand Up @@ -5960,7 +6003,10 @@ reduces them without incurring seq initialization"

ISequential
IEquiv
(-equiv [coll other] (equiv-sequential coll other))
(-equiv [coll other]
(if (instance? PersistentVector other)
(-equiv other coll)
(equiv-sequential coll other)))

ASeq
ISeq
Expand Down
1 change: 1 addition & 0 deletions src/test/cljs/cljs/primitives_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@
(is (= "cafrogbd" (let [jumble (fn [a b] (str (apply str (reverse (str a))) b))]
(reduce jumble "frog" "abcd"))))
(is (= [3] (nthnext [1 2 3] 2)))
(is (= (nthnext [1 2 3] 2) [3]))
(assert (not= 1 2))
(is (not (not= 1 1)))
(is (not (not-empty [])))
Expand Down