Skip to content
Merged
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
27 changes: 18 additions & 9 deletions src/main/cljs/cljs/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12603,10 +12603,14 @@ reduces them without incurring seq initialization"
(let [k (if-not (keyword? k) k (keyword->obj-map-key k))]
(if (string? k)
(if-not (nil? (scan-array 1 k strkeys))
(let [new-strobj (obj-clone strobj strkeys)]
(gobject/set new-strobj k v)
(ObjMap. meta strkeys new-strobj nil)) ;overwrite
(let [new-strobj (obj-clone strobj strkeys) ; append
(if (identical? v (gobject/get strobj k))
coll
; overwrite
(let [new-strobj (obj-clone strobj strkeys)]
(gobject/set new-strobj k v)
(ObjMap. meta strkeys new-strobj nil)))
; append
(let [new-strobj (obj-clone strobj strkeys)
new-keys (aclone strkeys)]
(gobject/set new-strobj k v)
(.push new-keys k)
Expand Down Expand Up @@ -12812,10 +12816,12 @@ reduces them without incurring seq initialization"
i (scan-array-equiv 2 k new-bucket)]
(aset new-hashobj h new-bucket)
(if (some? i)
(do
; found key, replace
(aset new-bucket (inc i) v)
(HashMap. meta count new-hashobj nil))
(if (identical? v (aget new-bucket (inc i)))
coll
(do
; found key, replace
(aset new-bucket (inc i) v)
(HashMap. meta count new-hashobj nil)))
(do
; did not find key, append
(.push new-bucket k v)
Expand Down Expand Up @@ -12954,7 +12960,10 @@ reduces them without incurring seq initialization"

ICollection
(-conj [coll o]
(Set. meta (assoc hash-map o o) nil))
(let [new-hash-map (assoc hash-map o o)]
(if (identical? new-hash-map hash-map)
coll
(Set. meta new-hash-map nil))))

IEmptyableCollection
(-empty [coll] (with-meta (. Set -EMPTY) meta))
Expand Down
8 changes: 8 additions & 0 deletions src/test/cljs/cljs/lite_collections_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
(= 1 (aget (clj->js (obj-map :x 1)) "x"))
(= 1 (aget (clj->js {:x 1}) "x")))

(deftest test-unchanged-identical?
(let [m (obj-map :foo 1)]
(identical? m (assoc m :foo 1)))
(let [m (simple-hash-map :foo 1)]
(identical? m (assoc m :foo 1)))
(let [s (simple-set [:foo])]
(identical? s (conj s :foo))))

(comment

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