Skip to content

Commit 249faa2

Browse files
authored
CLJS-3457: :lite-mode data structures should satisfy identical? if unchanged by conj (#276)
1 parent a761d54 commit 249faa2

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12603,10 +12603,14 @@ reduces them without incurring seq initialization"
1260312603
(let [k (if-not (keyword? k) k (keyword->obj-map-key k))]
1260412604
(if (string? k)
1260512605
(if-not (nil? (scan-array 1 k strkeys))
12606-
(let [new-strobj (obj-clone strobj strkeys)]
12607-
(gobject/set new-strobj k v)
12608-
(ObjMap. meta strkeys new-strobj nil)) ;overwrite
12609-
(let [new-strobj (obj-clone strobj strkeys) ; append
12606+
(if (identical? v (gobject/get strobj k))
12607+
coll
12608+
; overwrite
12609+
(let [new-strobj (obj-clone strobj strkeys)]
12610+
(gobject/set new-strobj k v)
12611+
(ObjMap. meta strkeys new-strobj nil)))
12612+
; append
12613+
(let [new-strobj (obj-clone strobj strkeys)
1261012614
new-keys (aclone strkeys)]
1261112615
(gobject/set new-strobj k v)
1261212616
(.push new-keys k)
@@ -12812,10 +12816,12 @@ reduces them without incurring seq initialization"
1281212816
i (scan-array-equiv 2 k new-bucket)]
1281312817
(aset new-hashobj h new-bucket)
1281412818
(if (some? i)
12815-
(do
12816-
; found key, replace
12817-
(aset new-bucket (inc i) v)
12818-
(HashMap. meta count new-hashobj nil))
12819+
(if (identical? v (aget new-bucket (inc i)))
12820+
coll
12821+
(do
12822+
; found key, replace
12823+
(aset new-bucket (inc i) v)
12824+
(HashMap. meta count new-hashobj nil)))
1281912825
(do
1282012826
; did not find key, append
1282112827
(.push new-bucket k v)
@@ -12954,7 +12960,10 @@ reduces them without incurring seq initialization"
1295412960

1295512961
ICollection
1295612962
(-conj [coll o]
12957-
(Set. meta (assoc hash-map o o) nil))
12963+
(let [new-hash-map (assoc hash-map o o)]
12964+
(if (identical? new-hash-map hash-map)
12965+
coll
12966+
(Set. meta new-hash-map nil))))
1295812967

1295912968
IEmptyableCollection
1296012969
(-empty [coll] (with-meta (. Set -EMPTY) meta))

src/test/cljs/cljs/lite_collections_test.cljs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
(= 1 (aget (clj->js (obj-map :x 1)) "x"))
2929
(= 1 (aget (clj->js {:x 1}) "x")))
3030

31+
(deftest test-unchanged-identical?
32+
(let [m (obj-map :foo 1)]
33+
(identical? m (assoc m :foo 1)))
34+
(let [m (simple-hash-map :foo 1)]
35+
(identical? m (assoc m :foo 1)))
36+
(let [s (simple-set [:foo])]
37+
(identical? s (conj s :foo))))
38+
3139
(comment
3240

3341
(require '[cljs.lite-collections-test] :reload)

0 commit comments

Comments
 (0)