diff mbox

[20/34] ptrlist: use the iterator API for DO_INSERT_CURRENT()

Message ID 20170707134002.49500-21-luc.vanoostenryck@gmail.com (mailing list archive)
State Rejected, archived
Headers show

Commit Message

Luc Van Oostenryck July 7, 2017, 1:39 p.m. UTC
---
 ptrlist.h | 42 ++++++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 20 deletions(-)
diff mbox

Patch

diff --git a/ptrlist.h b/ptrlist.h
index 0e6d30b99..ab2b13a3c 100644
--- a/ptrlist.h
+++ b/ptrlist.h
@@ -213,27 +213,29 @@  do {										\
 
 extern void split_ptr_list_head(struct ptr_list *);
 
-#define DO_SPLIT(ptr, __cur) do {							\
-	split_ptr_list_head(__cur.l);							\
-	if (__cur.n >= __cur.l->nr) {							\
-		__cur.n -= __cur.l->nr;							\
-		__cur.l = __cur.l->next;						\
-	};										\
-} while (0)
+static inline void ptr_cur_insert(struct ptr_cur *cur, void *new, void *ptr)
+{
+	void **this, **last;
+
+	if (cur->l->nr == LIST_NODE_NR) {
+		split_ptr_list_head(cur->l);
+		if (cur->n >= cur->l->nr) {
+			cur->n -= cur->l->nr;
+			cur->l = cur->l->next;
+		}
+	}
+	this = cur->l->list + cur->n;
+	last = cur->l->list + cur->l->nr - 1;
+	while (last >= this) {
+		last[1] = last[0];
+		last--;
+	}
+	*this = (new);
+	cur->l->nr++;
+}
 
-#define DO_INSERT_CURRENT(new, ptr, __cur) do {						\
-	void **__this, **__last;							\
-	if (__cur.l->nr == LIST_NODE_NR)						\
-		DO_SPLIT(ptr, __cur);							\
-	__this = __cur.l->list + __cur.n;						\
-	__last = __cur.l->list + __cur.l->nr - 1;					\
-	while (__last >= __this) {							\
-		__last[1] = __last[0];							\
-		__last--;								\
-	}										\
-	*__this = (new);								\
-	__cur.l->nr++;									\
-} while (0)
+#define DO_INSERT_CURRENT(new, ptr, __cur) \
+	ptr_cur_insert(&__cur, new, ptr)
 
 #define INSERT_CURRENT(new, ptr) \
 	DO_INSERT_CURRENT(new, ptr, __cur##ptr)