From 6ced2a50056acbf7caec404a1edfa3b07fa1ac5d Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Wed, 29 Dec 2021 10:48:03 +0100 Subject: feat: remove NULL-checks --- arraylist.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'arraylist.c') diff --git a/arraylist.c b/arraylist.c index bb4d0c2..a8cebb0 100644 --- a/arraylist.c +++ b/arraylist.c @@ -31,7 +31,7 @@ ArrayList_allocateArray(void *ptr, size_t nelem) void ArrayList_init(struct ArrayList *arrayList) { - assert(arrayList != NULL); + assert(arrayList); arrayList->array = NULL; arrayList->size = 0; @@ -42,7 +42,7 @@ struct ArrayList * ArrayList_new(void) { struct ArrayList *arrayList = malloc(sizeof *arrayList); - if ( arrayList != NULL ) { + if ( arrayList ) { ArrayList_init(arrayList); } return arrayList; @@ -51,7 +51,7 @@ ArrayList_new(void) void ArrayList_free(struct ArrayList *arrayList) { - assert(arrayList != NULL); + assert(arrayList); free(arrayList->array); ArrayList_init(arrayList); @@ -60,7 +60,7 @@ ArrayList_free(struct ArrayList *arrayList) void ArrayList_delete(struct ArrayList *arrayList) { - assert(arrayList != NULL); + assert(arrayList); ArrayList_free(arrayList); free(arrayList); @@ -69,7 +69,7 @@ ArrayList_delete(struct ArrayList *arrayList) static void ArrayList_growIfNeeded(struct ArrayList *arrayList) { - assert(arrayList != NULL); + assert(arrayList); if ( arrayList->size == arrayList->capacity ) { if ( arrayList->array == NULL ) { // leere Liste @@ -89,14 +89,14 @@ ArrayList_growIfNeeded(struct ArrayList *arrayList) arrayList->array = new_arrayList; } - assert(arrayList->array != NULL); + assert(arrayList->array); } } void ArrayList_append(struct ArrayList *arrayList, T *ptr) { - assert(arrayList != NULL); + assert(arrayList); ArrayList_growIfNeeded(arrayList); @@ -106,7 +106,7 @@ ArrayList_append(struct ArrayList *arrayList, T *ptr) void ArrayList_insertAt(struct ArrayList *arrayList, size_t idx, T *ptr) { - assert(arrayList != NULL); + assert(arrayList); assert(idx <= arrayList->size); // allow last position ArrayList_growIfNeeded(arrayList); @@ -119,7 +119,7 @@ ArrayList_insertAt(struct ArrayList *arrayList, size_t idx, T *ptr) T * ArrayList_getAt(struct ArrayList *arrayList, size_t idx) { - assert(arrayList != NULL); + assert(arrayList); assert(idx < arrayList->size); return arrayList->array[idx]; @@ -128,7 +128,7 @@ ArrayList_getAt(struct ArrayList *arrayList, size_t idx) size_t ArrayList_size(struct ArrayList *arrayList) { - assert(arrayList != NULL); + assert(arrayList); return arrayList->size; } @@ -136,7 +136,7 @@ ArrayList_size(struct ArrayList *arrayList) bool ArrayList_empty(struct ArrayList *arrayList) { - assert(arrayList != NULL); + assert(arrayList); return arrayList->size == 0; } @@ -144,10 +144,10 @@ ArrayList_empty(struct ArrayList *arrayList) void ArrayList_removeAt(struct ArrayList *arrayList, size_t idx, void clear_func(T *, void *), void *args) { - assert(arrayList != NULL); + assert(arrayList); assert(idx < arrayList->size); - if ( clear_func != NULL ) { + if ( clear_func ) { clear_func(arrayList->array[idx], args); } @@ -181,8 +181,8 @@ ArrayList_qsortHelper(void *ctx, const void *a, const void *b) void ArrayList_sort(struct ArrayList *arrayList, int cmp(const T *, const T *, void *), void *args) { - assert(arrayList != NULL); - assert(cmp != NULL); + assert(arrayList); + assert(cmp); struct qsortHelper_context context = { .cmp = cmp, @@ -196,9 +196,9 @@ ArrayList_sort(struct ArrayList *arrayList, int cmp(const T *, const T *, void * bool ArrayList_linearSearch(struct ArrayList *arrayList, void *key, int cmp(void *, const T *, void *), void *args, size_t *loc) { - assert(arrayList != NULL); - assert(cmp != NULL); - assert(loc != NULL); + assert(arrayList); + assert(cmp); + assert(loc); for ( size_t idx = 0; idx != arrayList->size; ++idx ) { if ( cmp(key, arrayList->array[idx], args) == 0 ) { @@ -227,9 +227,9 @@ ArrayList_bsearchHelper(const void *ctx, const void *el) bool ArrayList_binarySearch(struct ArrayList *arrayList, void *key, int cmp(void *, const T *, void *), void *args, size_t *loc) { - assert(arrayList != NULL); - assert(cmp != NULL); - assert(loc != NULL); + assert(arrayList); + assert(cmp); + assert(loc); struct bsearchHelper_context context = { .key = key, @@ -238,7 +238,7 @@ ArrayList_binarySearch(struct ArrayList *arrayList, void *key, int cmp(void *, c }; T **pos = bsearch(&context, arrayList->array, arrayList->size, sizeof(arrayList->array[0]), ArrayList_bsearchHelper); - if ( pos != NULL ) { + if ( pos ) { *loc = (size_t)(pos - arrayList->array); return true; } @@ -250,8 +250,8 @@ ArrayList_binarySearch(struct ArrayList *arrayList, void *key, int cmp(void *, c void ArrayList_shuffle(struct ArrayList *arrayList, size_t rng(size_t, void *), void *args) { - assert(arrayList != NULL); - assert(rng != NULL); + assert(arrayList); + assert(rng); if ( arrayList->size > 1 ) { for ( size_t i = arrayList->size - 1; i > 0; --i ) { -- cgit v1.3