diff options
Diffstat (limited to 'android/util.go')
| -rw-r--r-- | android/util.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/android/util.go b/android/util.go index 50bf5aa54..e17d7b213 100644 --- a/android/util.go +++ b/android/util.go @@ -351,15 +351,19 @@ func firstUniqueMap[T comparable](in []T) []T { return in[0:writeIndex] } -// reverseSliceInPlace reverses the elements of a slice in place. -func reverseSliceInPlace[T any](in []T) { +// ReverseSliceInPlace reverses the elements of a slice in place and returns it. +func ReverseSliceInPlace[T any](in []T) []T { for i, j := 0, len(in)-1; i < j; i, j = i+1, j-1 { in[i], in[j] = in[j], in[i] } + return in } -// reverseSlice returns a copy of a slice in reverse order. -func reverseSlice[T any](in []T) []T { +// ReverseSlice returns a copy of a slice in reverse order. +func ReverseSlice[T any](in []T) []T { + if in == nil { + return in + } out := make([]T, len(in)) for i := 0; i < len(in); i++ { out[i] = in[len(in)-1-i] |