From fd5ae91be85dbd10270e35e7bbffb54da3f771fd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=96=9C=E6=AC=A2?= <csharpwz@outlook.com>
Date: Wed, 15 Jan 2025 22:07:25 +0800
Subject: [PATCH] Update threadunsafe.go threadUnsafeSet.MarshalJSON

upgrade threadUnsafeSet.MarshalJSON by array json marshal
---
 threadunsafe.go | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/threadunsafe.go b/threadunsafe.go
index c95d32b..fcbbf60 100644
--- a/threadunsafe.go
+++ b/threadunsafe.go
@@ -324,18 +324,7 @@ func (s threadUnsafeSet[T]) Union(other Set[T]) Set[T] {
 
 // MarshalJSON creates a JSON array from the set, it marshals all elements
 func (s threadUnsafeSet[T]) MarshalJSON() ([]byte, error) {
-	items := make([]string, 0, s.Cardinality())
-
-	for elem := range s {
-		b, err := json.Marshal(elem)
-		if err != nil {
-			return nil, err
-		}
-
-		items = append(items, string(b))
-	}
-
-	return []byte(fmt.Sprintf("[%s]", strings.Join(items, ","))), nil
+	return json.Marshal(s.ToSlice())
 }
 
 // UnmarshalJSON recreates a set from a JSON array, it only decodes