[PATCH 07/13] ptrlist: remove extra ident level

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The list walking macros are relatively complex and the code they define
have often 5 or 6 level of nesting.

However, in a few places, a small rewrite of the code can save one
nesting level and this help to make the code more readable.

Make this change and reduce the indentation level.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 ptrlist.h | 65 ++++++++++++++++++++++++++-----------------------------
 1 file changed, 31 insertions(+), 34 deletions(-)

diff --git a/ptrlist.h b/ptrlist.h
index 037fe28ff..c28abce6d 100644
--- a/ptrlist.h
+++ b/ptrlist.h
@@ -157,44 +157,42 @@ static inline void *last_ptr_list(struct ptr_list *list)
 #define DO_FOR_EACH(head, ptr, __head, __list, __nr, PTR_ENTRY) do {			\
 	__typeof__(head) __head = head;							\
 	__typeof__(head) __list = head;							\
-	if (__head) {									\
-		do { int __nr;								\
-			for (__nr = 0; __nr < __list->nr; __nr++) {			\
-				do {							\
-					ptr = PTR_ENTRY(__list,__nr);			\
-					if (__list->rm && !ptr)				\
-						continue;				\
-					do {
+	if (!__head) break;								\
+	do { int __nr;									\
+		for (__nr = 0; __nr < __list->nr; __nr++) {				\
+			do {								\
+				ptr = PTR_ENTRY(__list,__nr);				\
+				if (__list->rm && !ptr)					\
+					continue;					\
+				do {
 
 #define DO_END_FOR_EACH(ptr, __head, __list, __nr)					\
-					} while (0);					\
 				} while (0);						\
-			}								\
-		} while ((__list = __list->next) != __head);				\
-	}										\
+			} while (0);							\
+		}									\
+	} while ((__list = __list->next) != __head);					\
 } while (0)
 
 #define DO_FOR_EACH_REVERSE(head, ptr, __head, __list, __nr, PTR_ENTRY) do {		\
 	__typeof__(head) __head = head;							\
 	__typeof__(head) __list = head;							\
-	if (__head) {									\
-		do { int __nr;								\
-			__list = __list->prev;						\
-			__nr = __list->nr;						\
-			while (--__nr >= 0) {						\
-				do {							\
-					ptr = PTR_ENTRY(__list,__nr);			\
-					if (__list->rm && !ptr)				\
-						continue;				\
-					do {
+	if (!head) break;								\
+	do { int __nr;									\
+		__list = __list->prev;							\
+		__nr = __list->nr;							\
+		while (--__nr >= 0) {							\
+			do {								\
+				ptr = PTR_ENTRY(__list,__nr);				\
+				if (__list->rm && !ptr)					\
+					continue;					\
+				do {
 
 
 #define DO_END_FOR_EACH_REVERSE(ptr, __head, __list, __nr)				\
-					} while (0);					\
 				} while (0);						\
-			}								\
-		} while (__list != __head);						\
-	}										\
+			} while (0);							\
+		}									\
+	} while (__list != __head);							\
 } while (0)
 
 #define DO_REVERSE(ptr, __head, __list, __nr, new, __newhead,				\
@@ -204,15 +202,14 @@ static inline void *last_ptr_list(struct ptr_list *list)
 	int __newnr = __nr;								\
 	new = ptr;									\
 	goto __inside##new;								\
-	if (1) {									\
-		do {									\
-			__newlist = __newlist->prev;					\
-			__newnr = __newlist->nr;					\
+	do {										\
+		__newlist = __newlist->prev;						\
+		__newnr = __newlist->nr;						\
 	__inside##new:									\
-			while (--__newnr >= 0) {					\
-				do {							\
-					new = PTR_ENTRY(__newlist,__newnr);		\
-					do {
+		while (--__newnr >= 0) {						\
+			do {								\
+				new = PTR_ENTRY(__newlist,__newnr);			\
+				do {
 
 #define RECURSE_PTR_REVERSE(ptr, new)							\
 	DO_REVERSE(ptr, __head##ptr, __list##ptr, __nr##ptr,				\
-- 
2.17.1

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux