mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-03 03:47:38 +03:00
Add compat func for clear
This commit is contained in:
parent
afa72012e5
commit
2a2dbf1971
2 changed files with 27 additions and 0 deletions
11
common/clear.go
Normal file
11
common/clear.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
//go:build go1.21
|
||||
|
||||
package common
|
||||
|
||||
func ClearArray[T ~[]E, E any](t T) {
|
||||
clear(t)
|
||||
}
|
||||
|
||||
func ClearMap[T ~map[K]V, K comparable, V any](t T) {
|
||||
clear(t)
|
||||
}
|
16
common/clear_compat.go
Normal file
16
common/clear_compat.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
//go:build !go1.21
|
||||
|
||||
package common
|
||||
|
||||
func ClearArray[T ~[]E, E any](t T) {
|
||||
var defaultValue E
|
||||
for i := range t {
|
||||
t[i] = defaultValue
|
||||
}
|
||||
}
|
||||
|
||||
func ClearMap[T ~map[K]V, K comparable, V any](t T) {
|
||||
for k := range t {
|
||||
delete(t, k)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue