mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 13:41:37 +00:00
8162e9033d
And refactor some code a bit, don't use bytes.Clone where type-specific helpers may be used instead. Close #2907. Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
30 lines
592 B
Go
30 lines
592 B
Go
/*
|
|
Package slice contains byte slice helpers.
|
|
*/
|
|
package slice
|
|
|
|
// CopyReverse returns a new byte slice containing reversed version of the
|
|
// original.
|
|
func CopyReverse(b []byte) []byte {
|
|
dest := make([]byte, len(b))
|
|
reverse(dest, b)
|
|
return dest
|
|
}
|
|
|
|
// Reverse does in-place reversing of byte slice.
|
|
func Reverse(b []byte) {
|
|
reverse(b, b)
|
|
}
|
|
|
|
func reverse(dst []byte, src []byte) {
|
|
for i, j := 0, len(src)-1; i <= j; i, j = i+1, j-1 {
|
|
dst[i], dst[j] = src[j], src[i]
|
|
}
|
|
}
|
|
|
|
// Clean wipes the data in b by filling it with zeros.
|
|
func Clean(b []byte) {
|
|
for i := range b {
|
|
b[i] = 0
|
|
}
|
|
}
|