Browse Source

micro-op bgp_node_[get|lookup]() and route_node_[get|lookup]()

  Reduce indirection for values that doesn't change in the loop.

Signed-off-by: Jorge Boncompte [DTI2] <jorge@dti2.net>
[adjusted after dropping previous patch]
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Jorge Boncompte [DTI2] 7 years ago
parent
commit
47d3b6078a
2 changed files with 22 additions and 14 deletions
  1. 11 7
      bgpd/bgp_table.c
  2. 11 7
      lib/table.c

+ 11 - 7
bgpd/bgp_table.c

@@ -289,16 +289,18 @@ struct bgp_node *
 bgp_node_lookup (const struct bgp_table *table, struct prefix *p)
 {
   struct bgp_node *node;
+  u_char prefixlen = p->prefixlen;
+  const u_char *prefix = &p->u.prefix;
 
   node = table->top;
 
-  while (node && node->p.prefixlen <= p->prefixlen && 
+  while (node && node->p.prefixlen <= prefixlen &&
 	 prefix_match (&node->p, p))
     {
-      if (node->p.prefixlen == p->prefixlen && node->info)
+      if (node->p.prefixlen == prefixlen && node->info)
 	return bgp_lock_node (node);
 
-      node = node->link[prefix_bit(&p->u.prefix, node->p.prefixlen)];
+      node = node->link[prefix_bit(prefix, node->p.prefixlen)];
     }
 
   return NULL;
@@ -311,19 +313,21 @@ bgp_node_get (struct bgp_table *const table, struct prefix *p)
   struct bgp_node *new;
   struct bgp_node *node;
   struct bgp_node *match;
+  u_char prefixlen = p->prefixlen;
+  const u_char *prefix = &p->u.prefix;
 
   match = NULL;
   node = table->top;
-  while (node && node->p.prefixlen <= p->prefixlen && 
+  while (node && node->p.prefixlen <= prefixlen &&
 	 prefix_match (&node->p, p))
     {
-      if (node->p.prefixlen == p->prefixlen)
+      if (node->p.prefixlen == prefixlen)
 	{
 	  bgp_lock_node (node);
 	  return node;
 	}
       match = node;
-      node = node->link[prefix_bit(&p->u.prefix, node->p.prefixlen)];
+      node = node->link[prefix_bit(prefix, node->p.prefixlen)];
     }
 
   if (node == NULL)
@@ -347,7 +351,7 @@ bgp_node_get (struct bgp_table *const table, struct prefix *p)
       else
 	table->top = new;
 
-      if (new->p.prefixlen != p->prefixlen)
+      if (new->p.prefixlen != prefixlen)
 	{
 	  match = new;
 	  new = bgp_node_set (table, p);

+ 11 - 7
lib/table.c

@@ -258,16 +258,18 @@ struct route_node *
 route_node_lookup (struct route_table *table, struct prefix *p)
 {
   struct route_node *node;
+  u_char prefixlen = p->prefixlen;
+  const u_char *prefix = &p->u.prefix;
 
   node = table->top;
 
-  while (node && node->p.prefixlen <= p->prefixlen && 
+  while (node && node->p.prefixlen <= prefixlen &&
 	 prefix_match (&node->p, p))
     {
-      if (node->p.prefixlen == p->prefixlen)
+      if (node->p.prefixlen == prefixlen)
         return node->info ? route_lock_node (node) : NULL;
 
-      node = node->link[prefix_bit(&p->u.prefix, node->p.prefixlen)];
+      node = node->link[prefix_bit(prefix, node->p.prefixlen)];
     }
 
   return NULL;
@@ -280,17 +282,19 @@ route_node_get (struct route_table *table, struct prefix *p)
   struct route_node *new;
   struct route_node *node;
   struct route_node *match;
+  u_char prefixlen = p->prefixlen;
+  const u_char *prefix = &p->u.prefix;
 
   match = NULL;
   node = table->top;
-  while (node && node->p.prefixlen <= p->prefixlen && 
+  while (node && node->p.prefixlen <= prefixlen &&
 	 prefix_match (&node->p, p))
     {
-      if (node->p.prefixlen == p->prefixlen)
+      if (node->p.prefixlen == prefixlen)
         return route_lock_node (node);
-      
+
       match = node;
-      node = node->link[prefix_bit(&p->u.prefix, node->p.prefixlen)];
+      node = node->link[prefix_bit(prefix, node->p.prefixlen)];
     }
 
   if (node == NULL)