mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
array: reverse empty arrays correctly
This commit is contained in:
parent
c1e095e587
commit
cbffbf3438
@ -328,6 +328,9 @@ pub fn (a mut array) push_many(val voidptr, size int) {
|
||||
// array.reverse returns a new array with the elements of
|
||||
// the original array in reverse order.
|
||||
pub fn (a array) reverse() array {
|
||||
if a.len < 2 {
|
||||
return a
|
||||
}
|
||||
arr := array{
|
||||
len: a.len
|
||||
cap: a.cap
|
||||
|
@ -266,6 +266,10 @@ fn test_reverse() {
|
||||
for i, _ in d {
|
||||
assert d[i] == b[b.len - i - 1]
|
||||
}
|
||||
|
||||
e := []int
|
||||
f := e.reverse()
|
||||
assert f.len == 0
|
||||
}
|
||||
|
||||
const (
|
||||
|
Loading…
Reference in New Issue
Block a user