File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ //go:build !go1.21
2+
3+ package mapset
4+
5+ func mapclone [T comparable ](m map [T ]struct {}) map [T ]struct {} {
6+ c := make (map [T ]struct {}, len (m ))
7+ for k := range m {
8+ c [k ] = struct {}{}
9+ }
10+ return c
11+ }
Original file line number Diff line number Diff line change 1+ //go:build go1.21
2+
3+ package mapset
4+
5+ import "maps"
6+
7+ func mapclone [T comparable ](m map [T ]struct {}) map [T ]struct {} {
8+ return maps .Clone (m )
9+ }
Original file line number Diff line number Diff line change @@ -82,11 +82,8 @@ func (s *threadUnsafeSet[T]) Clear() {
8282}
8383
8484func (s * threadUnsafeSet [T ]) Clone () Set [T ] {
85- clonedSet := newThreadUnsafeSetWithSize [T ](s .Cardinality ())
86- for elem := range * s {
87- clonedSet .add (elem )
88- }
89- return clonedSet
85+ t := threadUnsafeSet [T ](mapclone (* s ))
86+ return & t
9087}
9188
9289func (s * threadUnsafeSet [T ]) Contains (v ... T ) bool {
You can’t perform that action at this time.
0 commit comments