diff --git a/src/main/cljs/cljs/core.cljs b/src/main/cljs/cljs/core.cljs index 3515da790..3beaa425c 100644 --- a/src/main/cljs/cljs/core.cljs +++ b/src/main/cljs/cljs/core.cljs @@ -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) @@ -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) @@ -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)) diff --git a/src/test/cljs/cljs/lite_collections_test.cljs b/src/test/cljs/cljs/lite_collections_test.cljs index 16d0296c1..a96148f00 100644 --- a/src/test/cljs/cljs/lite_collections_test.cljs +++ b/src/test/cljs/cljs/lite_collections_test.cljs @@ -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)