Sun, 20 Apr 2025 10:41:25 +0200
some cxListIterator() variants now also allow NULL lists
CHANGELOG | file | annotate | diff | comparison | revisions | |
docs/Writerside/topics/about.md | file | annotate | diff | comparison | revisions | |
src/cx/list.h | file | annotate | diff | comparison | revisions |
--- a/CHANGELOG Sat Apr 19 14:43:16 2025 +0200 +++ b/CHANGELOG Sun Apr 20 10:41:25 2025 +0200 @@ -11,6 +11,7 @@ * changes grow strategy for the mempory pool to reduce reallocations * changes grow strategy for CxBuffer, which does now take the page size into account * changes the implementation of cx_strreplacen() for improved efficiency + * changes all cxListIterator() without index to also accept NULL as list argument * fixes unnecessary allocations in cx_strcat() family of functions * fixes errno value after failing cxBufferSeek() to be consistently EINVAL * fixes implementation of cxBufferTerminate()
--- a/docs/Writerside/topics/about.md Sat Apr 19 14:43:16 2025 +0200 +++ b/docs/Writerside/topics/about.md Sun Apr 20 10:41:25 2025 +0200 @@ -38,6 +38,7 @@ * changes grow strategy for the memory pool to reduce reallocations * changes grow strategy for CxBuffer, which does now take the page size into account * changes the implementation of cx_strreplacen() for improved efficiency +* changes all cxListIterator() without index to also accept NULL as list argument * fixes unnecessary allocations in cx_strcat() family of functions * fixes errno value after failing cxBufferSeek() to be consistently EINVAL * fixes implementation of cxBufferTerminate()
--- a/src/cx/list.h Sat Apr 19 14:43:16 2025 +0200 +++ b/src/cx/list.h Sun Apr 20 10:41:25 2025 +0200 @@ -203,6 +203,22 @@ }; /** + * Common type for all list implementations. + */ +typedef struct cx_list_s CxList; + +/** + * A shared instance of an empty list. + * + * Writing to that list is not allowed. + * + * You can use this is a placeholder for initializing CxList pointers + * for which you do not want to reserve memory right from the beginning. + */ +cx_attr_export +extern CxList *const cxEmptyList; + +/** * Default implementation of an array insert. * * This function uses the element insert function for each element of the array. @@ -336,11 +352,6 @@ ); /** - * Common type for all list implementations. - */ -typedef struct cx_list_s CxList; - -/** * Returns the number of elements currently stored in the list. * * @param list the list @@ -791,14 +802,14 @@ * * The returned iterator is position-aware. * - * If the list is empty, a past-the-end iterator will be returned. + * If the list is empty or @c NULL, a past-the-end iterator will be returned. * * @param list the list * @return a new iterator */ -cx_attr_nonnull cx_attr_nodiscard static inline CxIterator cxListIterator(const CxList *list) { + if (list == NULL) list = cxEmptyList; return list->cl->iterator(list, 0, false); } @@ -807,14 +818,14 @@ * * The returned iterator is position-aware. * - * If the list is empty, a past-the-end iterator will be returned. + * If the list is empty or @c NULL, a past-the-end iterator will be returned. * * @param list the list * @return a new iterator */ -cx_attr_nonnull cx_attr_nodiscard static inline CxIterator cxListMutIterator(CxList *list) { + if (list == NULL) list = cxEmptyList; return cxListMutIteratorAt(list, 0); } @@ -824,14 +835,14 @@ * * The returned iterator is position-aware. * - * If the list is empty, a past-the-end iterator will be returned. + * If the list is empty or @c NULL, a past-the-end iterator will be returned. * * @param list the list * @return a new iterator */ -cx_attr_nonnull cx_attr_nodiscard static inline CxIterator cxListBackwardsIterator(const CxList *list) { + if (list == NULL) list = cxEmptyList; return list->cl->iterator(list, list->collection.size - 1, true); } @@ -840,14 +851,14 @@ * * The returned iterator is position-aware. * - * If the list is empty, a past-the-end iterator will be returned. + * If the list is empty or @c NULL, a past-the-end iterator will be returned. * * @param list the list * @return a new iterator */ -cx_attr_nonnull cx_attr_nodiscard static inline CxIterator cxListMutBackwardsIterator(CxList *list) { + if (list == NULL) list = cxEmptyList; return cxListMutBackwardsIteratorAt(list, list->collection.size - 1); } @@ -982,17 +993,6 @@ cx_attr_export void cxListFree(CxList *list); -/** - * A shared instance of an empty list. - * - * Writing to that list is not allowed. - * - * You can use this is a placeholder for initializing CxList pointers - * for which you do not want to reserve memory right from the beginning. - */ -cx_attr_export -extern CxList *const cxEmptyList; - #ifdef __cplusplus } // extern "C"