Skip to content

Commit

Permalink
👔 up(arr,cflag): optimize some util and methods logic
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Mar 22, 2023
1 parent a56a93e commit 303b699
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions arrutil/arrutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ func RandomOne[T any](arr []T) T {

// Unique value in the given slice data.
func Unique[T ~string | comdef.XintOrFloat](list []T) []T {
if len(list) < 2 {
return list
}

valMap := make(map[T]struct{}, len(list))
uniArr := make([]T, 0, len(list))

Expand Down
2 changes: 2 additions & 0 deletions cflag/ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ func NewKVString() KVString {
func (s *KVString) Init() *KVString {
if s.Sep == "" {
s.Sep = comdef.EqualStr
}
if s.SMap == nil {
s.SMap = make(maputil.SMap)
}
return s
Expand Down

0 comments on commit 303b699

Please sign in to comment.