Skip to content

Commit 2e5790b

Browse files
slipsetmfikes
authored andcommitted
CLJS-2794 Return identity when with-meta is called with identical meta
1 parent 1b242bb commit 2e5790b

File tree

2 files changed

+111
-33
lines changed

2 files changed

+111
-33
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 109 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,9 @@ reduces them without incurring seq initialization"
16081608
(-meta [coll] meta)
16091609
IWithMeta
16101610
(-with-meta [coll new-meta]
1611-
(IndexedSeq. arr i new-meta))
1611+
(if (identical? new-meta meta)
1612+
coll
1613+
(IndexedSeq. arr i new-meta)))
16121614

16131615
ASeq
16141616
ISeq
@@ -1708,7 +1710,9 @@ reduces them without incurring seq initialization"
17081710
(-meta [coll] meta)
17091711
IWithMeta
17101712
(-with-meta [coll new-meta]
1711-
(RSeq. ci i new-meta))
1713+
(if (identical? new-meta meta)
1714+
coll
1715+
(RSeq. ci i new-meta)))
17121716

17131717
ISeqable
17141718
(-seq [coll] coll)
@@ -3063,7 +3067,10 @@ reduces them without incurring seq initialization"
30633067
(-clone [_] (List. meta first rest count __hash))
30643068

30653069
IWithMeta
3066-
(-with-meta [coll meta] (List. meta first rest count __hash))
3070+
(-with-meta [coll new-meta]
3071+
(if (identical? new-meta meta)
3072+
coll
3073+
(List. new-meta first rest count __hash)))
30673074

30683075
IMeta
30693076
(-meta [coll] meta)
@@ -3137,7 +3144,10 @@ reduces them without incurring seq initialization"
31373144
(-clone [_] (EmptyList. meta))
31383145

31393146
IWithMeta
3140-
(-with-meta [coll meta] (EmptyList. meta))
3147+
(-with-meta [coll new-meta]
3148+
(if (identical? new-meta meta)
3149+
coll
3150+
(EmptyList. new-meta)))
31413151

31423152
IMeta
31433153
(-meta [coll] meta)
@@ -3240,7 +3250,10 @@ reduces them without incurring seq initialization"
32403250
(-clone [_] (Cons. meta first rest __hash))
32413251

32423252
IWithMeta
3243-
(-with-meta [coll meta] (Cons. meta first rest __hash))
3253+
(-with-meta [coll new-meta]
3254+
(if (identical? new-meta meta)
3255+
coll
3256+
(Cons. new-meta first rest __hash)))
32443257

32453258
IMeta
32463259
(-meta [coll] meta)
@@ -3436,7 +3449,10 @@ reduces them without incurring seq initialization"
34363449
(not fn))
34373450

34383451
IWithMeta
3439-
(-with-meta [coll meta] (LazySeq. meta #(-seq coll) nil __hash))
3452+
(-with-meta [coll new-meta]
3453+
(if (identical? new-meta meta)
3454+
coll
3455+
(LazySeq. new-meta #(-seq coll) nil __hash)))
34403456

34413457
IMeta
34423458
(-meta [coll] meta)
@@ -3554,8 +3570,10 @@ reduces them without incurring seq initialization"
35543570
(-lastIndexOf coll x start))
35553571

35563572
IWithMeta
3557-
(-with-meta [coll m]
3558-
(ChunkedCons. chunk more m __hash))
3573+
(-with-meta [coll new-meta]
3574+
(if (identical? new-meta meta)
3575+
coll
3576+
(ChunkedCons. chunk more new-meta __hash)))
35593577

35603578
IMeta
35613579
(-meta [coll] meta)
@@ -4832,7 +4850,10 @@ reduces them without incurring seq initialization"
48324850
(some? current))
48334851

48344852
IWithMeta
4835-
(-with-meta [coll meta] (Cycle. meta all prev current _next))
4853+
(-with-meta [coll new-meta]
4854+
(if (identical? new-meta meta)
4855+
coll
4856+
(Cycle. new-meta all prev current _next)))
48364857

48374858
IMeta
48384859
(-meta [coll] meta)
@@ -4904,7 +4925,10 @@ reduces them without incurring seq initialization"
49044925
(-realized? [coll] false)
49054926

49064927
IWithMeta
4907-
(-with-meta [coll meta] (Repeat. meta count val next nil))
4928+
(-with-meta [coll new-meta]
4929+
(if (identical? new-meta meta)
4930+
coll
4931+
(Repeat. new-meta count val next nil)))
49084932

49094933
IMeta
49104934
(-meta [coll] meta)
@@ -5010,7 +5034,10 @@ reduces them without incurring seq initialization"
50105034
(not (identical? seed UNREALIZED-SEED)))
50115035

50125036
IWithMeta
5013-
(-with-meta [coll meta] (Iterate. meta f prev-seed seed next))
5037+
(-with-meta [coll new-meta]
5038+
(if (identical? new-meta meta)
5039+
coll
5040+
(Iterate. new-meta f prev-seed seed next)))
50145041

50155042
IMeta
50165043
(-meta [coll] meta)
@@ -5476,7 +5503,10 @@ reduces them without incurring seq initialization"
54765503
(-clone [_] (PersistentVector. meta cnt shift root tail __hash))
54775504

54785505
IWithMeta
5479-
(-with-meta [coll meta] (PersistentVector. meta cnt shift root tail __hash))
5506+
(-with-meta [coll new-meta]
5507+
(if (identical? new-meta meta)
5508+
coll
5509+
(PersistentVector. new-meta cnt shift root tail __hash)))
54805510

54815511
IMeta
54825512
(-meta [coll] meta)
@@ -5718,8 +5748,10 @@ reduces them without incurring seq initialization"
57185748
(-lastIndexOf coll x start))
57195749

57205750
IWithMeta
5721-
(-with-meta [coll m]
5722-
(chunked-seq vec node i off m))
5751+
(-with-meta [coll new-meta]
5752+
(if (identical? new-meta meta)
5753+
coll
5754+
(chunked-seq vec node i off new-meta)))
57235755
IMeta
57245756
(-meta [coll] meta)
57255757

@@ -5813,7 +5845,10 @@ reduces them without incurring seq initialization"
58135845
(-clone [_] (Subvec. meta v start end __hash))
58145846

58155847
IWithMeta
5816-
(-with-meta [coll meta] (build-subvec meta v start end __hash))
5848+
(-with-meta [coll new-meta]
5849+
(if (identical? new-meta meta)
5850+
coll
5851+
(build-subvec new-meta v start end __hash)))
58175852

58185853
IMeta
58195854
(-meta [coll] meta)
@@ -6172,7 +6207,10 @@ reduces them without incurring seq initialization"
61726207
(-lastIndexOf coll x start))
61736208

61746209
IWithMeta
6175-
(-with-meta [coll meta] (PersistentQueueSeq. meta front rear __hash))
6210+
(-with-meta [coll new-meta]
6211+
(if (identical? new-meta meta)
6212+
coll
6213+
(PersistentQueueSeq. new-meta front rear __hash)))
61766214

61776215
IMeta
61786216
(-meta [coll] meta)
@@ -6234,7 +6272,10 @@ reduces them without incurring seq initialization"
62346272
(PersistentQueueIter. front (-iterator rear)))
62356273

62366274
IWithMeta
6237-
(-with-meta [coll meta] (PersistentQueue. meta count front rear __hash))
6275+
(-with-meta [coll new-meta]
6276+
(if (identical? new-meta meta)
6277+
coll
6278+
(PersistentQueue. new-meta count front rear __hash)))
62386279

62396280
IMeta
62406281
(-meta [coll] meta)
@@ -6364,7 +6405,10 @@ reduces them without incurring seq initialization"
63646405
(-equiv this other))
63656406

63666407
IWithMeta
6367-
(-with-meta [coll meta] (ObjMap. meta keys strobj update-count __hash))
6408+
(-with-meta [coll new-meta]
6409+
(if (identical? new-meta meta)
6410+
coll
6411+
(ObjMap. new-meta keys strobj update-count __hash)))
63686412

63696413
IMeta
63706414
(-meta [coll] meta)
@@ -6710,7 +6754,9 @@ reduces them without incurring seq initialization"
67106754

67116755
IWithMeta
67126756
(-with-meta [coll new-meta]
6713-
(PersistentArrayMapSeq. arr i new-meta))
6757+
(if (identical? new-meta _meta)
6758+
coll
6759+
(PersistentArrayMapSeq. arr i new-meta)))
67146760

67156761
ICounted
67166762
(-count [coll]
@@ -6794,7 +6840,10 @@ reduces them without incurring seq initialization"
67946840
(-clone [_] (PersistentArrayMap. meta cnt arr __hash))
67956841

67966842
IWithMeta
6797-
(-with-meta [coll meta] (PersistentArrayMap. meta cnt arr __hash))
6843+
(-with-meta [coll new-meta]
6844+
(if (identical? new-meta meta)
6845+
coll
6846+
(PersistentArrayMap. new-meta cnt arr __hash)))
67986847

67996848
IMeta
68006849
(-meta [coll] meta)
@@ -7664,7 +7713,10 @@ reduces them without incurring seq initialization"
76647713
(-meta [coll] meta)
76657714

76667715
IWithMeta
7667-
(-with-meta [coll meta] (NodeSeq. meta nodes i s __hash))
7716+
(-with-meta [coll new-meta]
7717+
(if (identical? new-meta meta)
7718+
coll
7719+
(NodeSeq. new-meta nodes i s __hash)))
76687720

76697721
ICollection
76707722
(-conj [coll o] (cons o coll))
@@ -7742,7 +7794,10 @@ reduces them without incurring seq initialization"
77427794
(-meta [coll] meta)
77437795

77447796
IWithMeta
7745-
(-with-meta [coll meta] (ArrayNodeSeq. meta nodes i s __hash))
7797+
(-with-meta [coll new-meta]
7798+
(if (identical? new-meta meta)
7799+
coll
7800+
(ArrayNodeSeq. new-meta nodes i s __hash)))
77467801

77477802
ICollection
77487803
(-conj [coll o] (cons o coll))
@@ -7835,7 +7890,10 @@ reduces them without incurring seq initialization"
78357890
root-iter)))
78367891

78377892
IWithMeta
7838-
(-with-meta [coll meta] (PersistentHashMap. meta cnt root has-nil? nil-val __hash))
7893+
(-with-meta [coll new-meta]
7894+
(if (identical? new-meta meta)
7895+
coll
7896+
(PersistentHashMap. new-meta cnt root has-nil? nil-val __hash)))
78397897

78407898
IMeta
78417899
(-meta [coll] meta)
@@ -8161,8 +8219,10 @@ reduces them without incurring seq initialization"
81618219
(-meta [coll] meta)
81628220

81638221
IWithMeta
8164-
(-with-meta [coll meta]
8165-
(PersistentTreeMapSeq. meta stack ascending? cnt __hash))
8222+
(-with-meta [coll new-meta]
8223+
(if (identical? new-meta meta)
8224+
coll
8225+
(PersistentTreeMapSeq. new-meta stack ascending? cnt __hash)))
81668226

81678227
IReduce
81688228
(-reduce [coll f] (seq-reduce f coll))
@@ -8703,7 +8763,10 @@ reduces them without incurring seq initialization"
87038763
(-clone [_] (PersistentTreeMap. comp tree cnt meta __hash))
87048764

87058765
IWithMeta
8706-
(-with-meta [coll meta] (PersistentTreeMap. comp tree cnt meta __hash))
8766+
(-with-meta [coll new-meta]
8767+
(if (identical? new-meta meta)
8768+
coll
8769+
(PersistentTreeMap. comp tree cnt new-meta __hash)))
87078770

87088771
IMeta
87098772
(-meta [coll] meta)
@@ -8892,7 +8955,10 @@ reduces them without incurring seq initialization"
88928955
(-meta [coll] _meta)
88938956

88948957
IWithMeta
8895-
(-with-meta [coll new-meta] (KeySeq. mseq new-meta))
8958+
(-with-meta [coll new-meta]
8959+
(if (identical? new-meta _meta)
8960+
coll
8961+
(KeySeq. mseq new-meta)))
88968962

88978963
ISeqable
88988964
(-seq [coll] coll)
@@ -8968,7 +9034,10 @@ reduces them without incurring seq initialization"
89689034
(-meta [coll] _meta)
89699035

89709036
IWithMeta
8971-
(-with-meta [coll new-meta] (ValSeq. mseq new-meta))
9037+
(-with-meta [coll new-meta]
9038+
(if (identical? new-meta _meta)
9039+
coll
9040+
(ValSeq. mseq new-meta)))
89729041

89739042
ISeqable
89749043
(-seq [coll] coll)
@@ -9105,7 +9174,10 @@ reduces them without incurring seq initialization"
91059174
(HashSetIter. (-iterator hash-map)))
91069175

91079176
IWithMeta
9108-
(-with-meta [coll meta] (PersistentHashSet. meta hash-map __hash))
9177+
(-with-meta [coll new-meta]
9178+
(if (identical? new-meta meta)
9179+
coll
9180+
(PersistentHashSet. new-meta hash-map __hash)))
91099181

91109182
IMeta
91119183
(-meta [coll] meta)
@@ -9259,7 +9331,10 @@ reduces them without incurring seq initialization"
92599331
(-clone [_] (PersistentTreeSet. meta tree-map __hash))
92609332

92619333
IWithMeta
9262-
(-with-meta [coll meta] (PersistentTreeSet. meta tree-map __hash))
9334+
(-with-meta [coll new-meta]
9335+
(if (identical? new-meta meta)
9336+
coll
9337+
(PersistentTreeSet. new-meta tree-map __hash)))
92639338

92649339
IMeta
92659340
(-meta [coll] meta)
@@ -9622,7 +9697,10 @@ reduces them without incurring seq initialization"
96229697
(-clone [_] (Range. meta start end step chunk chunk-next __hash))
96239698

96249699
IWithMeta
9625-
(-with-meta [rng meta] (Range. meta start end step chunk chunk-next __hash))
9700+
(-with-meta [rng new-meta]
9701+
(if (identical? new-meta meta)
9702+
rng
9703+
(Range. new-meta start end step chunk chunk-next __hash)))
96269704

96279705
IMeta
96289706
(-meta [rng] meta)

src/test/cljs/cljs/collections_test.cljs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,12 +1006,12 @@
10061006
(deftest test-cljs-2442
10071007
(testing "set ctor"
10081008
(let [coll #{1 2}]
1009-
(is (not (identical? coll (set coll)))))
1009+
(is (identical? coll (set coll))))
10101010
(is (= #{1 2} (set #{1 2})))
10111011
(is (nil? (meta (set ^:a #{1 2})))))
10121012
(testing "vec ctor"
10131013
(let [coll [1 2]]
1014-
(is (not (identical? coll (vec coll)))))
1014+
(is (identical? coll (vec coll))))
10151015
(is (= [1 2] (vec [1 2])))
10161016
(is (nil? (meta (vec ^:a [1 2]))))
10171017
(let [coll (vec (first {:a 1}))]

0 commit comments

Comments
 (0)