[esnacc-dev] [PATCH 2/7] exp-buf: Rewrite the list walk code

Aaron Conole aconole at bytheb.org
Tue Dec 20 17:14:09 UTC 2016


This code was a giant mess;  it's all one simple base-case as well.  So, we
rewrite it to do the 'right thing'.

Signed-off-by: Aaron Conole <aconole at bytheb.org>
---
 c-lib/src/exp-buf.c | 40 +++++++++-------------------------------
 1 file changed, 9 insertions(+), 31 deletions(-)

diff --git a/c-lib/src/exp-buf.c b/c-lib/src/exp-buf.c
index f6a0660..a86a8c8 100644
--- a/c-lib/src/exp-buf.c
+++ b/c-lib/src/exp-buf.c
@@ -364,37 +364,15 @@ void
 ExpBufResetInReadMode PARAMS ((b),
     ExpBuf **b)
 {
-	ExpBuf *nextPtr = (ExpBuf *)0;
-	ExpBuf *retVal = (ExpBuf *)0;
-    (*b)->curr = (*b)->dataStart;
-    (*b)->readError = 0;
-    (*b)->writeError = 1; /* catch wrong mode errors */
-	/* Get the Previous Pointer */
-	nextPtr = (*b)->next;
-	if (nextPtr == NULL)
-		retVal = (*b);
-	else
-		retVal = nextPtr;
-	if (nextPtr != NULL)
-	{
-
-		while (nextPtr)
-		{
-			nextPtr->curr = nextPtr->dataStart;
-			nextPtr->readError = 0;
-			nextPtr->writeError = 1; /* catch wrong mode errors */
-			nextPtr = nextPtr->next;
-			if (nextPtr)
-				retVal = nextPtr;
-		}
-	}
-	else
-	{
-		retVal->curr = retVal->dataStart;
-		retVal->readError = 0;
-		retVal->writeError = 1;
-	}
-	*b = retVal;
+    ExpBuf **pp = b;
+    ExpBuf *p = *pp;
+    while ((p = *pp) != NULL) {
+        p->curr = p->dataStart;
+        p->readError = 0;
+        p->writeError = 1;
+        *b = p;
+        pp = &(p->next);
+    }
 }
 
 /*
-- 
2.7.4




More information about the dev mailing list