]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: Add tail check before nexthop insertion
authorStephen Worley <sworley@cumulusnetworks.com>
Mon, 5 Aug 2019 19:30:05 +0000 (15:30 -0400)
committerStephen Worley <sworley@cumulusnetworks.com>
Mon, 19 Aug 2019 17:55:50 +0000 (13:55 -0400)
Add a tail check to see if we can just put the nexthop
at the end of the already sorted list before iteration.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
lib/nexthop_group.c

index 5602018b30c3889e48dbeb954f270b447f529722..abe2096cecbd17e57bef2e8f325bae1e98fb9ce8 100644 (file)
@@ -60,6 +60,16 @@ nexthop_group_cmd_compare(const struct nexthop_group_cmd *nhgc1,
        return strcmp(nhgc1->name, nhgc2->name);
 }
 
+static struct nexthop *nexthop_group_tail(const struct nexthop_group *nhg)
+{
+       struct nexthop *nexthop = nhg->nexthop;
+
+       while (nexthop && nexthop->next)
+               nexthop = nexthop->next;
+
+       return nexthop;
+}
+
 uint8_t nexthop_group_nexthop_num(const struct nexthop_group *nhg)
 {
        struct nexthop *nhop;
@@ -129,7 +139,20 @@ void _nexthop_add(struct nexthop **target, struct nexthop *nexthop)
 void _nexthop_group_add_sorted(struct nexthop_group *nhg,
                               struct nexthop *nexthop)
 {
-       struct nexthop *position, *prev;
+       struct nexthop *position, *prev, *tail;
+
+       /* Try to just append to the end first
+        * This trust it is already sorted
+        */
+
+       tail = nexthop_group_tail(nhg);
+
+       if (tail && (nexthop_cmp(tail, nexthop) < 0)) {
+               tail->next = nexthop;
+               nexthop->prev = tail;
+
+               return;
+       }
 
        for (position = nhg->nexthop, prev = NULL; position;
             prev = position, position = position->next) {