Merge pull request #6309 from Faker-09/xar_iter_reset

core:container/xar reset iterators for easy reuse
This commit is contained in:
Jeroen van Rijn
2026-02-20 19:12:33 +01:00
committed by GitHub
2 changed files with 4 additions and 0 deletions

View File

@@ -136,6 +136,7 @@ freelist_iterate_by_val :: proc(it: ^Freelist_Iterator($T, $SHIFT)) -> (val: T,
}
it.idx += 1
}
it.idx = 0
return
}
@@ -150,5 +151,6 @@ freelist_iterate_by_ptr :: proc(it: ^Freelist_Iterator($T, $SHIFT)) -> (val: ^T,
}
it.idx += 1
}
it.idx = 0
return
}

View File

@@ -476,6 +476,7 @@ Advance the iterator and returns the next element.
*/
array_iterate_by_val :: proc(it: ^Array_Iterator($T, $SHIFT)) -> (val: T, idx: int, ok: bool) {
if it.idx >= it.xar.len {
it.idx = 0
return
}
val = array_get(it.xar, it.idx)
@@ -497,6 +498,7 @@ Advance the iterator and returns a pointer to the next element.
*/
array_iterate_by_ptr :: proc(it: ^Array_Iterator($T, $SHIFT)) -> (val: ^T, idx: int, ok: bool) {
if it.idx >= it.xar.len {
it.idx = 0
return
}
val = array_get_ptr(it.xar, it.idx)