Ethereal-dev: [Ethereal-dev] Small performance optimization to ip_to_str()

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Yaniv Kaul <ykaul@xxxxxxxxxxxx>
Date: Mon, 24 Jan 2005 21:36:33 +0200
Attached diff.
It change a while()->do, to do->while() and removes a variable (and an assignment to it).

Index: to_str.c
===================================================================
--- to_str.c	(revision 13165)
+++ to_str.c	(working copy)
@@ -141,7 +141,7 @@
 gchar *
 ip_to_str(const guint8 *ad) {
   static gchar  str[4][16];
-  static int   cur_idx=0;
+  static guint32   cur_idx=0;
   gchar *cur;
 
   cur_idx++;
@@ -197,34 +197,33 @@
 {
 	register gchar const *p;
 	register gchar *b=buf;
-	register gchar c;
 
 	p=fast_strings[*ad++];
-	while((c=*p)){
-		*b++=c;
+	do {
+		*b++=*p;
 		p++;
-	}
+	} while(*p);
 	*b++='.';
 
 	p=fast_strings[*ad++];
-	while((c=*p)){
-		*b++=c;
+	do {
+		*b++=*p;
 		p++;
-	}
+	} while(*p);
 	*b++='.';
 
 	p=fast_strings[*ad++];
-	while((c=*p)){
-		*b++=c;
+	do {
+		*b++=*p;
 		p++;
-	}
+	} while(*p);
 	*b++='.';
 
-	p=fast_strings[*ad++];
-	while((c=*p)){
-		*b++=c;
+	p=fast_strings[*ad];
+	do {
+		*b++=*p;
 		p++;
-	}
+	} while(*p);
 	*b=0;
 }