From: NeilBrown Date: Thu, 26 Nov 2015 23:40:39 +0000 (+1100) Subject: tlist_for_each{,_entry}_continue* no longer need head of list. X-Git-Tag: lca2016~177 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=b3fda9132b827aadb00c56a0f810ae8f97034ca1;p=edlib.git tlist_for_each{,_entry}_continue* no longer need head of list. We can use the type information to stop at the right place. Signed-off-by: NeilBrown --- diff --git a/core-mark.c b/core-mark.c index 66f16c28..41ff70cc 100644 --- a/core-mark.c +++ b/core-mark.c @@ -348,10 +348,9 @@ struct mark *doc_first_mark(struct doc *d, int view) struct mark *doc_next_mark(struct doc *d, struct mark *m) { - int view = m->viewnum; struct tlist_head *tl = &m->view; - tlist_for_each_continue(tl, &d->views[view].head) + tlist_for_each_continue(tl, GRP_HEAD) if (TLIST_TYPE(tl) == GRP_MARK) return tlist_entry(tl, struct mark, view); return NULL; @@ -578,7 +577,7 @@ static void point_forward_to_mark(struct point *p, struct mark *m) pnear = p; ptmp = p; - tlist_for_each_entry_continue(ptmp, &d->points, m.view) { + tlist_for_each_entry_continue(ptmp, GRP_HEAD, m.view) { if (ptmp->m.seq < m->seq) pnear = ptmp; else @@ -599,7 +598,7 @@ static void point_forward_to_mark(struct point *p, struct mark *m) if (!d->views[i].notify) continue; tl = &pnear->links->lists[i]; - tlist_for_each_continue(tl, &d->views[i].head) { + tlist_for_each_continue(tl, GRP_HEAD) { struct mark *mtmp; if (TLIST_TYPE(tl) != GRP_MARK) break; @@ -632,7 +631,7 @@ static void point_backward_to_mark(struct point *p, struct mark *m) pnear = p; ptmp = p; - tlist_for_each_entry_continue_reverse(ptmp, &d->points, m.view) { + tlist_for_each_entry_continue_reverse(ptmp, GRP_HEAD, m.view) { if (ptmp->m.seq > m->seq) pnear = ptmp; else @@ -653,7 +652,7 @@ static void point_backward_to_mark(struct point *p, struct mark *m) if (!d->views[i].notify) continue; tl = &pnear->links->lists[i]; - tlist_for_each_continue_reverse(tl, &d->views[i].head) { + tlist_for_each_continue_reverse(tl, GRP_HEAD) { struct mark *mtmp; if (TLIST_TYPE(tl) != GRP_MARK) break; diff --git a/list.h b/list.h index d7e2f7e5..300f7161 100644 --- a/list.h +++ b/list.h @@ -608,27 +608,27 @@ static inline void tlist_del_init(struct tlist_head *entry) /** * tlist_for_each_continue - continue iteration over tlist * @pos: the struct tlist_head * to use as a loop cursor. - * @head: the head for your list. + * @head_typef: the the type of the head for your list. * * Continue to iterate over tlist, continuing after * the current position. */ -#define tlist_for_each_continue(pos, head) \ +#define tlist_for_each_continue(pos, head_type) \ for (pos = TLIST_PTR(pos->next); \ - pos != (head); \ + TLIST_TYPE(pos) != (head_type); \ pos = TLIST_PTR(pos->next)) /** * list_for_each_continue_reverse - iterate backwards from the given point * @pos: the struct tlist_head * to use as a loop cursor. - * @head: the head for your list. + * @head: the type of the head for your list. * * Start to iterate over list of given type backwards, continuing after * the current position. */ -#define tlist_for_each_continue_reverse(pos, head) \ +#define tlist_for_each_continue_reverse(pos, head_type) \ for (pos = TLIST_PTR(pos->prev); \ - pos != (head); \ + TLIST_TYPE(pos) != (head_type); \ pos = TLIST_PTR(pos->prev)) /** @@ -647,29 +647,29 @@ static inline void tlist_del_init(struct tlist_head *entry) /** * tlist_for_each_entry_continue - continue iteration over list of given type * @pos: the type * to use as a loop cursor. - * @head: the head for your list. + * @head_type: type of pointer in the head for your list. * @member: the name of the tlist_head within the struct. * * Continue to iterate over list of given type, continuing after * the current position. */ -#define tlist_for_each_entry_continue(pos, head, member) \ +#define tlist_for_each_entry_continue(pos, head_type, member) \ for (pos = tlist_next_entry(pos, member); \ - &pos->member != (head); \ + TLIST_TYPE(&pos->member) != (head_type); \ pos = tlist_next_entry(pos, member)) /** * list_for_each_entry_continue_reverse - iterate backwards from the given point * @pos: the type * to use as a loop cursor. - * @head: the head for your list. + * @head_type: type of pointer in the head for your list. * @member: the name of the list_head within the struct. * * Start to iterate over list of given type backwards, continuing after * the current position. */ -#define tlist_for_each_entry_continue_reverse(pos, head, member) \ +#define tlist_for_each_entry_continue_reverse(pos, head_type, member) \ for (pos = tlist_prev_entry(pos, member); \ - &pos->member != (head); \ + TLIST_TYPE(&pos->member) != (head_type); \ pos = tlist_prev_entry(pos, member)) #endif /* __LIST_H__ */