# HG changeset patch # User Mike Becker # Date 1668960360 -3600 # Node ID b0bdff7d8203811102eb173b50f3140ecc32e484 # Parent 21082350a590a96e7db1524dc71e2cfc0abddd41 #219: cx_arl_remove short-circuit for last element diff -r 21082350a590 -r b0bdff7d8203 src/array_list.c --- a/src/array_list.c Sun Nov 20 16:58:51 2022 +0100 +++ b/src/array_list.c Sun Nov 20 17:06:00 2022 +0100 @@ -250,9 +250,14 @@ return 1; } - cx_array_list *arl = (cx_array_list *) list; + /* short-circuit removal of last element */ + if (index == list->size - 1) { + list->size--; + return 0; + } /* just move the elements starting at index to the left */ + cx_array_list *arl = (cx_array_list *) list; int result = cx_array_copy( &arl->data, &list->size,