neo-go/pkg/util/array.go
Evgenii Stratonikov 24bb66e606 util: fix a bug with not copying slice of len=1 in ArrayReverse
ArrayReverse copies it's argument only if it's len is > 1.
It needs to be consistent in all cases.
2020-02-06 12:15:35 +03:00

10 lines
251 B
Go

package util
// ArrayReverse returns a reversed version of the given byte slice.
func ArrayReverse(b []byte) []byte {
dest := make([]byte, len(b))
for i, j := 0, len(b)-1; i <= j; i, j = i+1, j-1 {
dest[i], dest[j] = b[j], b[i]
}
return dest
}