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 --- dlist.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'dlist.c') diff --git a/dlist.c b/dlist.c index bb0ead9..55e42d7 100644 --- a/dlist.c +++ b/dlist.c @@ -47,7 +47,7 @@ create_element(T data) struct dlist_element *element; element = malloc(sizeof *element); - if ( element != NULL ) { + if ( element ) { element->data = data; } @@ -62,7 +62,7 @@ dlist_push_front(struct dlist *dlist, T data) struct dlist_element *element; element = create_element(data); - if ( element != NULL ) { + if ( element ) { element->prev = NULL; /* Vorgänger ist in jedem Fall NULL */ if ( dlist_empty(dlist) ) { @@ -90,7 +90,7 @@ dlist_push_back(struct dlist *dlist, T data) struct dlist_element *element; element = create_element(data); - if ( element != NULL ) { + if ( element ) { element->next = NULL; /* Nachfolger ist in jedem Fall NULL */ if ( dlist_empty(dlist) ) { @@ -115,7 +115,7 @@ dlist_push_back(struct dlist *dlist, T data) bool dlist_pop_front(struct dlist *dlist, T *data) { - if ( dlist->head != NULL ) { + if ( dlist->head ) { struct dlist_element *element = dlist->head; dlist->head = element->next; @@ -125,7 +125,7 @@ dlist_pop_front(struct dlist *dlist, T *data) else element->next->prev = NULL; - if ( data != NULL ) { + if ( data ) { *data = element->data; } free(element); @@ -141,7 +141,7 @@ dlist_pop_front(struct dlist *dlist, T *data) bool dlist_pop_back(struct dlist *dlist, T *data) { - if ( dlist->head != NULL ) { + if ( dlist->head ) { struct dlist_element *element = dlist->tail; dlist->tail = element->prev; @@ -151,7 +151,7 @@ dlist_pop_back(struct dlist *dlist, T *data) else element->prev->next = NULL; - if ( data != NULL ) { + if ( data ) { *data = element->data; } free(element); @@ -170,7 +170,7 @@ dlist_insert_next(struct dlist *dlist, struct dlist_element *element, T data) struct dlist_element *new_element; new_element = create_element(data); - if ( new_element != NULL ) { + if ( new_element ) { if ( dlist->head == NULL ) { dlist->head = new_element; dlist->head->prev = NULL; @@ -203,7 +203,7 @@ dlist_insert_prev(struct dlist *dlist, struct dlist_element *element, T data) struct dlist_element *new_element; new_element = create_element(data); - if ( new_element != NULL ) { + if ( new_element ) { if ( dlist->head == NULL ) { dlist->head = new_element; dlist->head->prev = NULL; @@ -322,11 +322,11 @@ dlist_merge(struct dlist *list1, struct dlist *list2) *e1 = list1->head, *e2 = list2->head; - while ( e1 != NULL && e2 != NULL ) // Solange in e1 UND e2 Elemente sind... + while ( e1 && e2 ) // Solange in e1 UND e2 Elemente sind... { if ( e1->data < e2->data ) { e1->prev = cur; - if ( cur != NULL ) + if ( cur ) cur->next = e1; else head = e1; @@ -335,7 +335,7 @@ dlist_merge(struct dlist *list1, struct dlist *list2) } else { e2->prev = cur; - if ( cur != NULL ) + if ( cur ) cur->next = e2; else head = e2; @@ -344,25 +344,25 @@ dlist_merge(struct dlist *list1, struct dlist *list2) } } - if ( e1 != NULL ) // in e1 sind noch Elemente vorhanden! + if ( e1 ) // in e1 sind noch Elemente vorhanden! { assert(e2 == NULL); e1->prev = cur; - if ( cur != NULL ) + if ( cur ) cur->next = e1; else head = e1; // list1->tail zeigt bereits auf das letzte Element in list1 } - else /* if ( e2 != NULL ) */ + else /* if ( e2 ) */ { assert(e1 == NULL); - assert(e2 != NULL); + assert(e2); e2->prev = cur; - if ( cur != NULL ) + if ( cur ) cur->next = e2; else head = e2; @@ -392,7 +392,7 @@ dlist_sort(struct dlist *list) struct dlist_element *slow = list->head, *fast = list->head->next; - while ( fast != NULL && fast->next != NULL ) + while ( fast && fast->next ) slow = slow->next, fast = fast->next->next; struct dlist list1 = { .head = list->head, .tail = slow }, -- cgit v1.3