Sun, 20 Nov 2022 17:06:00 +0100
#219: cx_arl_remove short-circuit for last element
src/array_list.c | file | annotate | diff | comparison | revisions |
1.1 --- a/src/array_list.c Sun Nov 20 16:58:51 2022 +0100 1.2 +++ b/src/array_list.c Sun Nov 20 17:06:00 2022 +0100 1.3 @@ -250,9 +250,14 @@ 1.4 return 1; 1.5 } 1.6 1.7 - cx_array_list *arl = (cx_array_list *) list; 1.8 + /* short-circuit removal of last element */ 1.9 + if (index == list->size - 1) { 1.10 + list->size--; 1.11 + return 0; 1.12 + } 1.13 1.14 /* just move the elements starting at index to the left */ 1.15 + cx_array_list *arl = (cx_array_list *) list; 1.16 int result = cx_array_copy( 1.17 &arl->data, 1.18 &list->size,