[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-ha-dev
Subject:    [Linux-ha-dev] [patch 04/10] Use memset to set mask in find_if()
From:       Simon Horman <horms () verge ! net ! au>
Date:       2007-04-13 7:02:34
Message-ID: 20070413070507.692713767 () tabatha ! lab ! ultramonkey ! org
[Download RAW message or body]

By using memset instead of a small for loop the code becomes
a lot more compact without altering its behaviour. I think this is a good
thing :)

Index: heartbeat-ipv6addr/resources/OCF/IPv6addr.c
===================================================================
--- heartbeat-ipv6addr.orig/resources/OCF/IPv6addr.c	2007-04-13 15:45:43.000000000 +0900
+++ heartbeat-ipv6addr/resources/OCF/IPv6addr.c	2007-04-13 15:45:43.000000000 +0900
@@ -476,17 +476,13 @@
 		inet_pton(AF_INET6, addr6, &addr);
 
 		/* Make the mask based on prefix length */
-        	for (i = 0; i < 16; i++) {
-                	mask.s6_addr[i] = 0xff;
-        	}
-        	if (plen < 128) {
-                	n = plen / 8;
-                	for (i = 15; i>n; i--) {
-                        	mask.s6_addr[i] = 0x0;
-                	}
-                	s = 8 - plen % 8;
-                	mask.s6_addr[n] <<= s;
-        	}
+		memset(mask.s6_addr, 0xff, 16);
+		if (plen < 128) {
+			n = plen / 8;
+			memset(mask.s6_addr + n + 1, 0, 15 - n);
+			s = 8 - plen % 8;
+			mask.s6_addr[n] = 0xff << s;
+		}
 
 		/* compare addr and addr_target */
 		same = TRUE;

--

-- 
Horms
  H: http://www.vergenet.net/~horms/
  W: http://www.valinux.co.jp/en/

_______________________________________________________
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic