]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: optimize loops on [e]community_hash_make()
authorJorge Boncompte [DTI2] <jorge@dti2.net>
Mon, 7 May 2012 16:52:55 +0000 (16:52 +0000)
committerDavid Lamparter <equinox@opensourcerouting.org>
Tue, 22 May 2012 18:25:44 +0000 (20:25 +0200)
  This change reduces loop count. Less jumps.

* bgp_community.c: One loop per community.
* bgp_ecommunity.c: One loop per ecommunity.

Signed-off-by: Jorge Boncompte [DTI2] <jorge@dti2.net>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
bgpd/bgp_community.c
bgpd/bgp_ecommunity.c

index 2ba45f6e4e8b65ffb26f989db6bdc8bc7e2fbc42..fc1bef88b7bf63b2dc6196249d0a06fc4b868f19 100644 (file)
@@ -394,16 +394,19 @@ community_str (struct community *com)
 unsigned int
 community_hash_make (struct community *com)
 {
+  unsigned char *pnt = (unsigned char *)com->val;
+  int size = com->size * 4;
+  unsigned int key = 0;
   int c;
-  unsigned int key;
-  unsigned char *pnt;
 
-  key = 0;
-  pnt = (unsigned char *)com->val;
-  
-  for(c = 0; c < com->size * 4; c++)
-    key += pnt[c];
-      
+  for (c = 0; c < size; c += 4)
+    {
+      key += pnt[c];
+      key += pnt[c + 1];
+      key += pnt[c + 2];
+      key += pnt[c + 3];
+    }
+
   return key;
 }
 
index 9f4aaa4bf0745da41b7691673d1a27fbb6cf3da2..5722425e1d5b8efe206c66bb0ddc6bf7e7e6872d 100644 (file)
@@ -233,15 +233,22 @@ unsigned int
 ecommunity_hash_make (void *arg)
 {
   const struct ecommunity *ecom = arg;
+  int size = ecom->size * ECOMMUNITY_SIZE;
+  u_int8_t *pnt = ecom->val;
+  unsigned int key = 0;
   int c;
-  unsigned int key;
-  u_int8_t *pnt;
 
-  key = 0;
-  pnt = ecom->val;
-  
-  for (c = 0; c < ecom->size * ECOMMUNITY_SIZE; c++)
-    key += pnt[c];
+  for (c = 0; c < size; c += ECOMMUNITY_SIZE)
+    {
+      key += pnt[c];
+      key += pnt[c + 1];
+      key += pnt[c + 2];
+      key += pnt[c + 3];
+      key += pnt[c + 4];
+      key += pnt[c + 5];
+      key += pnt[c + 6];
+      key += pnt[c + 7];
+    }
 
   return key;
 }