diff -r fcfe8c5e9fe1 -r 27e67e725d35 ucx/dlist.c --- a/ucx/dlist.c Thu Oct 11 08:42:56 2012 +0200 +++ b/ucx/dlist.c Thu Oct 11 11:42:31 2012 +0200 @@ -1,6 +1,7 @@ #include "dlist.h" -UcxDlist *ucx_dlist_clone(UcxDlist *l, copy_func fnc, void *data) { +UcxDlist *restrict ucx_dlist_clone(UcxDlist *restrict l, + copy_func fnc, void *data) { UcxDlist *ret = NULL; while (l != NULL) { if (fnc != NULL) { @@ -13,7 +14,8 @@ return ret; } -int ucx_dlist_equals(UcxDlist *l1, UcxDlist *l2, cmp_func fnc, void* data) { +int ucx_dlist_equals(const UcxDlist *l1, const UcxDlist *l2, + cmp_func fnc, void* data) { if (l1 == l2) return 1; while (l1 != NULL && l2 != NULL) { @@ -66,7 +68,7 @@ return nl; } -UcxDlist *ucx_dlist_concat(UcxDlist *l1, UcxDlist *l2) { +UcxDlist *ucx_dlist_concat(UcxDlist *restrict l1, UcxDlist *restrict l2) { if (l1 == NULL) { return l2; } else { @@ -77,32 +79,32 @@ } } -UcxDlist *ucx_dlist_last(UcxDlist *l) { +UcxDlist *ucx_dlist_last(const UcxDlist *l) { if (l == NULL) return NULL; - UcxDlist *e = l; + const UcxDlist *e = l; while (e->next != NULL) { e = e->next; } - return e; + return (UcxDlist*)e; } -UcxDlist *ucx_dlist_get(UcxDlist *l, int index) { +UcxDlist *ucx_dlist_get(const UcxDlist *l, int index) { if (l == NULL) return NULL; - UcxDlist *e = l; + const UcxDlist *e = l; while (e->next != NULL && index > 0) { e = e->next; index--; } - return index == 0 ? e : NULL; + return (UcxDlist*)(index == 0 ? e : NULL); } -size_t ucx_dlist_size(UcxDlist *l) { +size_t ucx_dlist_size(const UcxDlist *l) { if (l == NULL) return 0; - UcxDlist *e = l; + const UcxDlist *e = l; size_t s = 1; while (e->next != NULL) { e = e->next; @@ -113,14 +115,14 @@ } UcxDlist *ucx_dlist_sort_merge(int length, - UcxDlist* ls, UcxDlist* rs, UcxDlist* le, UcxDlist* re, + UcxDlist* restrict ls, UcxDlist* restrict le, UcxDlist* restrict re, cmp_func fnc, void* data) { UcxDlist *sorted[length]; UcxDlist *rc, *lc; - lc = ls; rc = rs; + lc = ls; rc = le; int n = 0; - while (lc != le && rc != re) { + while (lc && lc != le && rc != re) { if (fnc(lc->data, rc->data, data) <= 0) { sorted[n] = lc; lc = lc->next; @@ -130,12 +132,12 @@ } n++; } - while (lc != le) { + while (lc && lc != le) { sorted[n] = lc; lc = lc->next; n++; } - while (rc != re) { + while (rc && rc != re) { sorted[n] = rc; rc = rc->next; n++; @@ -160,7 +162,7 @@ UcxDlist *lc; int ln = 1; - UcxDlist *ls = l, *le; + UcxDlist *restrict ls = l, *restrict le, *restrict re; lc = ls; while (lc->next != NULL && fnc(lc->next->data, lc->data, data) > 0) { lc = lc->next; @@ -168,13 +170,12 @@ } le = lc->next; - UcxDlist *rs = le, *re; - if (rs == NULL) { + if (le == NULL) { return l; // this list is already sorted :) } else { UcxDlist *rc; int rn = 1; - rc = rs; + rc = le; while (rc->next != NULL && fnc(rc->next->data, rc->data, data) > 0) { rc = rc->next; rn++; @@ -190,27 +191,26 @@ // {ls,...,le->prev} and {rs,...,re->prev} are sorted - merge them UcxDlist *sorted = ucx_dlist_sort_merge(ln+rn, - ls, rs, le, re, + ls, le, re, fnc, data); // merge sorted list with (also sorted) remainder l = ucx_dlist_sort_merge(ln+rn+remainder_length, - sorted, remainder, NULL, NULL, - fnc, data); + sorted, remainder, NULL, fnc, data); return l; } } /* dlist specific functions */ -UcxDlist *ucx_dlist_first(UcxDlist *l) { +UcxDlist *ucx_dlist_first(const UcxDlist *l) { if (l == NULL) return NULL; - UcxDlist *e = l; + const UcxDlist *e = l; while (e->prev != NULL) { e = e->prev; } - return e; + return (UcxDlist *)e; } UcxDlist *ucx_dlist_remove(UcxDlist *l, UcxDlist *e) {