#219: cx_arl_remove short-circuit for last element

Sun, 20 Nov 2022 17:06:00 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 20 Nov 2022 17:06:00 +0100
changeset 624
b0bdff7d8203
parent 623
21082350a590
child 625
a4c4a50c067a

#219: cx_arl_remove short-circuit for last element

src/array_list.c file | annotate | diff | comparison | revisions
--- 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,

mercurial