Re: [PATCH] lib/vsprintf.c: Add "%pI6c" - print pointer as compressed ipv6 address

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jens Rosenboom
Date: Monday, August 17, 2009 - 8:18 am

On Sat, 2009-08-15 at 08:24 -0700, Joe Perches wrote:

Two small optimizations:

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 9b79536..a80ef3d 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -677,12 +677,11 @@ static char *ip6_compressed_string(char *p, const
struct in6_addr *addr)
 	int j;
 	int range;
 	unsigned char zerolength[8];
-	int longest = 0;
+	int longest = 1;
 	int colonpos = -1;
 	u16 word;
 	u8 hi;
 	u8 lo;
-	bool printhi;
 	bool needcolon = false;
 	bool useIPv4 = ipv6_addr_v4mapped(addr) || ipv6_addr_is_isatap(addr);
 
@@ -707,8 +706,6 @@ static char *ip6_compressed_string(char *p, const
struct in6_addr *addr)
 			colonpos = i;
 		}
 	}
-	if (colonpos != -1 && zerolength[colonpos] < 2)
-		colonpos = -1;
 
 	for (i = 0; i < range; i++) {
 		if (i == colonpos) {
@@ -729,15 +726,13 @@ static char *ip6_compressed_string(char *p, const
struct in6_addr *addr)
 		word = ntohs(addr->s6_addr16[i]);
 		hi = word >> 8;
 		lo = word & 0xff;
-		printhi = false;
 		if (hi) {
 			if (hi > 0x0f)
 				p = pack_hex_byte(p, hi);
 			else
 				*p++ = hex_asc_lo(hi);
-			printhi = true;
 		}
-		if (printhi || lo > 0x0f)
+		if (hi || lo > 0x0f)
 			p = pack_hex_byte(p, lo);
 		else
 			*p++ = hex_asc_lo(lo);

Also I'm wondering whether it makes sense to pull the format code
checking into all the sub-routines. It might be easier to maintain if it
is all kept together in pointer().

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [RFC] ipv6: Change %pI6 format to output compacted add ..., Christoph Hellwig, (Thu Aug 13, 7:18 am)
Re: [PATCH] lib/vsprintf.c: Add "%pI6c" - print pointer as ..., Jens Rosenboom, (Mon Aug 17, 8:18 am)