diff --git a/src/main/cljs/cljs/core.cljs b/src/main/cljs/cljs/core.cljs index 3beaa425c..82bd82c6b 100644 --- a/src/main/cljs/cljs/core.cljs +++ b/src/main/cljs/cljs/core.cljs @@ -9308,7 +9308,10 @@ reduces them without incurring seq initialization" ICollection (-conj [coll o] - (PersistentHashSet. meta (assoc hash-map o nil) nil)) + (let [m (-assoc hash-map o nil)] + (if (identical? m hash-map) + coll + (PersistentHashSet. meta m nil)))) IEmptyableCollection (-empty [coll] (-with-meta (.-EMPTY PersistentHashSet) meta)) @@ -9345,7 +9348,10 @@ reduces them without incurring seq initialization" ISet (-disjoin [coll v] - (PersistentHashSet. meta (-dissoc hash-map v) nil)) + (let [m (-dissoc hash-map v)] + (if (identical? m hash-map) + coll + (PersistentHashSet. meta m nil)))) IFn (-invoke [coll k] @@ -9463,7 +9469,10 @@ reduces them without incurring seq initialization" ICollection (-conj [coll o] - (PersistentTreeSet. meta (assoc tree-map o nil) nil)) + (let [m (-assoc tree-map o nil)] + (if (identical? m tree-map) + coll + (PersistentTreeSet. meta m nil)))) IEmptyableCollection (-empty [coll] (PersistentTreeSet. meta (-empty tree-map) 0)) @@ -9517,7 +9526,10 @@ reduces them without incurring seq initialization" ISet (-disjoin [coll v] - (PersistentTreeSet. meta (dissoc tree-map v) nil)) + (let [m (-dissoc tree-map v)] + (if (identical? m tree-map) + coll + (PersistentTreeSet. meta m nil)))) IFn (-invoke [coll k] @@ -13002,7 +13014,10 @@ reduces them without incurring seq initialization" ISet (-disjoin [coll v] - (Set. meta (-dissoc hash-map v) nil)) + (let [new-hash-map (-dissoc hash-map v)] + (if (identical? new-hash-map hash-map) + coll + (Set. meta new-hash-map nil)))) IEditableCollection (-as-transient [coll] diff --git a/src/test/cljs/cljs/core_test.cljs b/src/test/cljs/cljs/core_test.cljs index 5d887d313..83f1a65ef 100644 --- a/src/test/cljs/cljs/core_test.cljs +++ b/src/test/cljs/cljs/core_test.cljs @@ -737,6 +737,27 @@ (is (= #{1 2} (hash-set 1 2 2))) (is (= #{1 2} (apply hash-set [1 2 2])))) +(deftest test-ordered-set + (is (= #{1 2} (sorted-set 1 2 2))) + (is (= [1 2 3] (seq (sorted-set 2 3 1)))) + (is (= #{1 2} (apply sorted-set [1 2 2])))) + +(deftest test-3454-conj + (is (= #{1 2 3} (conj #{1 2} 3))) + (is (= #{1 2 3} (conj (sorted-set 1 2) 3))) + (let [s #{1 2} + ss (sorted-set 1 2)] + (is (identical? s (conj s 2))) + (is (identical? ss (conj ss 2))))) + +(deftest test-3454-disj + (is (= #{1 2} (disj #{1 2 3} 3))) + (is (= #{1 2} (disj (sorted-set 1 2 3) 3))) + (let [s #{1 2} + ss (sorted-set 1 2)] + (is (identical? s (disj s 3))) + (is (identical? ss (disj ss 3))))) + (deftest test-585 (is (= (last (map identity (into [] (range 32)))) 31)) (is (= (into #{} (range 32))