Reverse swaps the order of elements in the slice so that the first become the last, and so on.
(s interface{})
| 91 | // Reverse swaps the order of elements in the slice so that the first become the |
| 92 | // last, and so on. |
| 93 | func Reverse(s interface{}) { |
| 94 | slice := getSlice(s) |
| 95 | tmp := reflect.New(slice.Type().Elem()).Elem() |
| 96 | for i, c, m := 0, slice.Len(), slice.Len()/2; i < m; i++ { |
| 97 | j := c - i - 1 |
| 98 | a, b := slice.Index(i), slice.Index(j) |
| 99 | tmp.Set(a) |
| 100 | a.Set(b) |
| 101 | b.Set(tmp) |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | // Bytes returns a byte-slice from the given unsafe pointer of the given |
| 106 | // size in bytes. |