]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Nest: Avoid unnecessary net_format() in 'show route' command
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Thu, 2 Dec 2021 03:05:17 +0000 (04:05 +0100)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Sun, 6 Feb 2022 22:27:13 +0000 (23:27 +0100)
When output of 'show route' command was generated, the net_format() was
called for each network prematurely, even if the result was not needed.

Fix the code to call net_format() only when needed. This makes queries
that process many networks but show only few (e.g. 'show route where ..',
or 'show route count') much faster (like 5x - 10x faster).

nest/rt-show.c

index d8abab5f18f1858e8dc068d165f0e550feee5d65..ea1f918c420822f7440e180f65a051fe1e5a87d2 100644 (file)
@@ -111,10 +111,9 @@ rt_show_net(struct cli *c, net *n, struct rt_show_data *d)
   ASSUME(!d->export_mode || ec);
 
   int first = 1;
+  int first_show = 1;
   int pass = 0;
 
-  bsnprintf(ia, sizeof(ia), "%N", n->n.addr);
-
   for (e = n->routes; e; e = e->next)
     {
       if (rte_is_filtered(e) != d->filtered)
@@ -188,10 +187,17 @@ rt_show_net(struct cli *c, net *n, struct rt_show_data *d)
        goto skip;
 
       if (d->stats < 2)
+      {
+       if (first_show)
+         net_format(n->n.addr, ia, sizeof(ia));
+       else
+         ia[0] = 0;
+
        rt_show_rte(c, ia, e, d, (e->net->routes == ee));
+       first_show = 0;
+      }
 
       d->show_counter++;
-      ia[0] = 0;
 
     skip:
       if (e != ee)