mirror of
https://github.com/ruby/ruby.git
synced 2026-01-27 04:24:23 +00:00
Implement rb_darray_swap_remove
This commit is contained in:
parent
099da884fe
commit
16626d500d
Notes:
git
2025-12-25 14:19:02 +00:00
14
darray.h
14
darray.h
@ -72,6 +72,20 @@
|
||||
(*(ptr_to_ary))->meta.size++; \
|
||||
} while (0)
|
||||
|
||||
/* Removes the element at idx and replaces it with the last element.
|
||||
* ptr_to_ary and idx is evaluated multiple times.
|
||||
* Warning: not bounds checked.
|
||||
*
|
||||
* void rb_darray_swap_remove(rb_darray(T) *ptr_to_ary, size_t idx);
|
||||
*/
|
||||
#define rb_darray_swap_remove(ptr_to_ary, idx) do { \
|
||||
size_t _darray_size = rb_darray_size(*(ptr_to_ary)); \
|
||||
if ((idx) != _darray_size - 1) { \
|
||||
(*(ptr_to_ary))->data[idx] = (*(ptr_to_ary))->data[_darray_size - 1]; \
|
||||
} \
|
||||
(*(ptr_to_ary))->meta.size--; \
|
||||
} while (0)
|
||||
|
||||
// Iterate over items of the array in a for loop
|
||||
//
|
||||
#define rb_darray_foreach(ary, idx_name, elem_ptr_var) \
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user