[quagga-dev 9295] [PATCH 05/25] bgpd: optimize loops on [e]community_hash_make()

Jorge Boncompte [DTI2] jorge at dti2.net
Mon May 7 18:52:55 BST 2012


From: "Jorge Boncompte [DTI2]" <jorge at dti2.net>

  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 at dti2.net>
---
 bgpd/bgp_community.c  |   19 +++++++++++--------
 bgpd/bgp_ecommunity.c |   21 ++++++++++++++-------
 2 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/bgpd/bgp_community.c b/bgpd/bgp_community.c
index 2ba45f6..fc1bef8 100644
--- a/bgpd/bgp_community.c
+++ b/bgpd/bgp_community.c
@@ -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;
 }
 
diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c
index 9f4aaa4..5722425 100644
--- a/bgpd/bgp_ecommunity.c
+++ b/bgpd/bgp_ecommunity.c
@@ -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;
 }
-- 
1.7.8.3





More information about the Quagga-dev mailing list