]> git.neil.brown.name Git - edlib.git/commitdiff
tlist_for_each{,_entry}_continue* no longer need head of list.
authorNeilBrown <neil@brown.name>
Thu, 26 Nov 2015 23:40:39 +0000 (10:40 +1100)
committerNeilBrown <neil@brown.name>
Thu, 26 Nov 2015 23:43:57 +0000 (10:43 +1100)
We can use the type information to stop at the right place.

Signed-off-by: NeilBrown <neil@brown.name>
core-mark.c
list.h

index 66f16c2811feedf9e25c3a4446a9ea385b9095c4..41ff70cc14e56c3f74688348a6a69d45bbf4f6f4 100644 (file)
@@ -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 d7e2f7e50850e99a68a672ce2d7627137fb10df5..300f7161f9fc25f9502756e9610fe590ba6f162a 100644 (file)
--- 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__ */