1.1 --- a/src/cx/list.h Sun Nov 20 21:08:36 2022 +0100 1.2 +++ b/src/cx/list.h Wed Nov 23 22:40:55 2022 +0100 1.3 @@ -130,6 +130,15 @@ 1.4 ); 1.5 1.6 /** 1.7 + * Member function for adding multiple elements. 1.8 + */ 1.9 + size_t (*add_array)( 1.10 + struct cx_list_s *list, 1.11 + void const *array, 1.12 + size_t n 1.13 + ); 1.14 + 1.15 + /** 1.16 * Member function for inserting an element. 1.17 */ 1.18 int (*insert)( 1.19 @@ -209,6 +218,7 @@ 1.20 * @param list the list 1.21 * @param elem a pointer to the element to add 1.22 * @return zero on success, non-zero on memory allocation failure 1.23 + * @see cxListAddArray() 1.24 */ 1.25 __attribute__((__nonnull__)) 1.26 static inline int cxListAdd( 1.27 @@ -219,6 +229,28 @@ 1.28 } 1.29 1.30 /** 1.31 + * Adds multiple items to the end of the list. 1.32 + * 1.33 + * This method is more efficient than invoking cxListAdd() multiple times. 1.34 + * 1.35 + * If there is not enough memory to add all elements, the returned value is 1.36 + * less than \p n. 1.37 + * 1.38 + * @param list the list 1.39 + * @param array a pointer to the elements to add 1.40 + * @param n the number of elements to add 1.41 + * @return the number of added elements 1.42 + */ 1.43 +__attribute__((__nonnull__)) 1.44 +static inline size_t cxListAddArray( 1.45 + CxList *list, 1.46 + void const *array, 1.47 + size_t n 1.48 +) { 1.49 + return list->cl->add_array(list, array, n); 1.50 +} 1.51 + 1.52 +/** 1.53 * Inserts an item at the specified index. 1.54 * 1.55 * If \p index equals the list \c size, this is effectively cxListAdd().